【问题标题】: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)
希望它对你有用。