我在设置QToolButton的QToolButton属性(稍后也是QPushButton的属性)时遇到了问题,但我认为问题也会发生在那里。我的每个自定义按钮(分别从QToolButton和QPushButton继承)必须有3种状态--非活动状态、运行状态和错误状态。
非活动:
style = 'border-top-right-radius: ' + str(self.cornerRadius) + 'px; border-bottom-right-radius: ' + str(self.cornerRadius) + 'px; border-top-left-radius: ' + str(self.cornerRadius) + 'px; border-bottom-left-radius: ' + str(self.cornerRadius) + 'px; border-image: url("' + self.icon + '"); background: none;'运行:
style = 'border-top-right-radius: ' + str(self.cornerRadius) + 'px; border-bottom-right-radius: ' + str(self.cornerRadius) + 'px; border-top-left-radius: ' + str(self.cornerRadius) + 'px; border-bottom-left-radius: ' + str(self.cornerRadius) + 'px; border-image: url("' + self.icon + '"); background: rgb(89, 205, 139);'错误:
style = 'border-top-right-radius: ' + str(self.cornerRadius) + 'px; border-bottom-right-radius: ' + str(self.cornerRadius) + 'px; border-top-left-radius: ' + str(self.cornerRadius) + 'px; border-bottom-left-radius: ' + str(self.cornerRadius) + 'px; border-image: url("' + self.icon + '"); background: rgb(215, 56, 56);'其中,self.cornerRadius是用来确定按钮圆度(以像素为单位)的某个数字,而self.icon是从某个地方检索到的图标。
我在按钮的构造函数中所做的(以及其他简单的初始化)是
self.setStyleSheet(style)按钮的clicked()信号连接到同一类中的一个插槽,在该槽中,状态将更改(以及使用self.setStyleSheet(...)的样式),以了解系统的新状态。
由于一些未知的原因,我的工具提示接收到它“属于”的按钮的样式更改:

我已经仔细检查了Qt文档,我看不出有什么理由解释这种行为.我根本不想改变工具提示的风格。有什么办法解决这个问题吗?
发布于 2016-04-20 15:17:13
我将问题解释为:
如何避免将一种小部件类型的样式与另一种小部件类型重叠?
请注意:
myObj.setStyleSheet("QPushButton {border: 0.05em solid lightgray;}" )
只需用例如QType { ... }的类型将样式表括起来即可。
我只处理C++ Qt,但认为PyQt使用相同的样式表系统。
https://stackoverflow.com/questions/36746520
复制相似问题