python - 如何在 QlineEdit 中更改单个字符串的颜色
问题描述
我正在使用计算器,当我单击“+”按钮时,我希望“+”为绿色而不是白色,而不改变数字的白色
这是按钮“+”的代码:
def plus(self):
splus=self.QlineEdit.text()
self.lineEdit.setText(splus+"+")
为了让我的问题简单明了,我希望输出是这样的:
解决方案
您可以尝试使用切换小部件颜色
splus.setStyleSheet("QLineEdit { background: rgb(xxx,xxx,xxx); selection-
background-color: rgb(xxx,xxx,xxx); }")
被 QLineEdit 的 clicked 事件触发为:
splus.clicked.connect(self.toggleColors)
希望对你有效。
推荐阅读
- python - 如何根据索引值对熊猫数据框进行分组?
- python - 逐段读取 JSON
- python - 如何使用 matplotlib 中的分类列为散点图着色?
- javascript - Javascript:未捕获的类型错误:在每种情况下都无法在帧处读取未定义的属性“循环”
- python - 如何使用在熊猫中非唯一的 id 字段将数据框从宽到长重塑为多列?
- r - .rmd 和 .Rmd 文件有区别吗?
- flutter - setState 没有在 Flutter 中更新 UI
- sql - 递归 SQL 查询将数据从父级泄漏到子级
- vb.net - IIS Edge 浏览器地址栏显示“关于:空白”而不是“正在加载”,并且焦点保留在地址栏中
- javascript - 将要执行的函数传递给引导模式