【问题标题】:How to Change a single strings color within a QlineEdit如何在 QlineEdit 中更改单个字符串的颜色
【发布时间】:2020-05-30 06:17:03
【问题描述】:

我正在使用计算器,当我点击“+”按钮时,我希望“+”为绿色而不是白色,而不改变数字的白色

这是按钮“+”的代码:

def plus(self):
    splus=self.QlineEdit.text()
    self.lineEdit.setText(splus+"+")

为了让我的问题简单明了,我希望输出是这样的:

【问题讨论】:

    标签: python python-3.x colors pyqt5 qlineedit


    【解决方案1】:

    您可以尝试切换小部件颜色

        splus.setStyleSheet("QLineEdit { background: rgb(xxx,xxx,xxx); selection- 
        background-color: rgb(xxx,xxx,xxx); }")
    

    被 QLineEdit 的 clicked 事件触发为:

        splus.clicked.connect(self.toggleColors) 
    

    希望它对你有用。

    【讨论】:

      猜你喜欢
      • 2014-08-08
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 1970-01-01
      • 2015-01-29
      • 1970-01-01
      • 2011-08-30
      • 1970-01-01
      相关资源
      最近更新 更多