在PyQt4中用Python设置QPushButton文本颜色
我想在我的图形界面上创建一些可以点击的蓝色文字,类似于HTML中的超链接!我正在使用Python 2.6和PyQt4。我之前成功设置过QLabel的文字颜色,但现在记不起来是怎么做的了,即使记得也不能点击。所以我转向了QPushButton,我可以像这样把它做成平面的:
testbutton = qt.QPushButton("Test")
testbutton.setFlat(True)
到目前为止,我的搜索结果都是C++和C#的方法,找不到Python的对应方法!
如果有人能告诉我怎么改变文字颜色,或者提供其他实现这个功能的方法,我会非常感激!
3 个回答
0
testbutton.setStyleSheet("background-color: #00FF00; color: #00FF00;")
这里的意思是: “background-color”是你按钮的背景颜色。 “color”是按钮上文字的颜色。
3
你可以使用你的 QPushButton
的 palette
属性,把你想要的蓝色应用到它的 ButtonText
颜色角色上:
testbutton = qt.QPushButton("Test")
testbutton.setFlat(True)
palette = qt.QPalette(testbutton.palette()) # make a copy of the palette
palette.setColor(qt.QPalette.ButtonText, qt.QColor('blue'))
testbutton.setPalette(palette) # assign new palette
7
你可以使用一个 样式表。
testbutton.setStyleSheet('QPushButton {color: blue}')