我有一个qtcombobox。我试图使用qss样式表添加一些样式,但它没有正确呈现。您在下面看到的白色背景是不受欢迎的。
照片:
我的代码样式:
QWidget
{
color: #eff0f1;
background-color: #31363b;
selection-background-color:#3daee9;
selection-color: #eff0f1;
background-clip: border;
border-image: none;
border: 0px transparent black;
outline: 0;
}
QComboBox
{
selection-background-color: #3daee9;
border-style: solid;
border: 1px solid #76797C;
border-radius: 2px;
padding: 5px;
min-width: 75px;
}
QComboBox:hover,QPushButton:hover,QAbstractSpinBox:hover,QLineEdit:hover,QTextEdit:hover,QPlainTextEdit:hover,QAbstractView:hover,QTreeView:hover
{
border: 1px solid #3daee9;
color: #eff0f1;
}
QComboBox:on
{
padding-top: 3px;
padding-left: 4px;
selection-background-color: #4a4a4a;
}
QComboBox QAbstractItemView
{
background-color: #232629;
border-radius: 2px;
border: 1px solid #76797C;
selection-background-color: #3daee9;
}
QComboBox::drop-down
{
subcontrol-origin: padding;
subcontrol-position: top right;
width: 15px;
border-left-width: 0px;
border-left-color: darkgray;
border-left-style: solid;
border-top-right-radius: 3px;
border-bottom-right-radius: 3px;
}
QComboBox::down-arrow
{
image: url(:/qss_icons/rc/down_arrow_disabled.png);
}
QComboBox::down-arrow:on, QComboBox::down-arrow:hover,
QComboBox::down-arrow:focus
{
image: url(:/qss_icons/rc/down_arrow.png);
}
什么可以导致最内部保持白色? 对于它的价值,下拉菜单正确造型。不知道是什么搞乱它使bg白色的一部分。
编辑:所以我已经使用这个样式表创建了一个小测试用例,并且最小化和qcombobox在那里工作。有很多代码触及了这个qcombobox,所以其他东西可能搞乱它但我不知道从哪里开始或者缩小范围。任何提示/建议都非常感谢。我已经尝试过评论其他setstylesheet命令和明显的基础知识。
答案 0 :(得分:1)
出于某种原因,样式表规则似乎没有级联到组合框中的行编辑。唯一的解决方案似乎是直接应用样式表:
self.combo.lineEdit().setStylesheet('background-color: red')
但这可能不适用于所有窗口小部件样式(例如,它似乎不适用于“Windows”样式)。
修改强>:
以下是我用于测试的内容:
from PySide import QtCore, QtGui
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.button = QtGui.QPushButton('Test', self)
self.button.clicked.connect(self.handleButton)
self.combo = QtGui.QComboBox(self)
self.combo.setEditable(True)
self.edit = QtGui.QLineEdit(self)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.button)
layout.addWidget(self.edit)
layout.addWidget(self.combo)
self.setStyleSheet("""
QWidget
{
background-color: yellow;
}
QComboBox
{
background-color: blue;
}
QLineEdit
{
background-color: red;
}
""")
def handleButton(self):
self.combo.lineEdit().setStyleSheet(self.styleSheet())
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.setGeometry(600, 200, 300, 100)
window.show()
sys.exit(app.exec_())
以下是我在Linux上获得的结果:
单击“测试”按钮可以设置组合线编辑的背景。我还尝试了其他一些选择器,如QComboBox > QLineEdit
,QLineEdit#foobar
等 - 但它们都没有任何效果。