我正在尝试将 qss 应用到组合框以使项目被选中或悬停在其上以具有高度为 30 和圆角的蓝色矩形,这是组合框 itslef 上的 qss 的补充。
self.b2 = QComboBox(self)
temp = QListView()
temp.setStyleSheet(""" QItemView::item { min-height: 35px; min-width: 50px; outline:none; }QItemView::item:selected { color: black; background: lightgray;}""")
self.b2.setView(QListView())
self.b2.addItems(['UX Research', 'Mobile Design', 'Visual Design','UX/UI Design','Illustration'])
self.b2.setFixedSize(220, 38)
self.b2.move(24, 24)
self.b2.setPlaceholderText("Choose")
self.b2.setStyleSheet("""
QComboBox {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.8,
stop:0 rgb(71, 78, 83),
stop:1 rgb(49, 54, 58));
border: none;
border-radius: 19px;
color: #f2f2f2;
font-size: 14px;
padding-left:16px;
}
QComboBox:hover {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.8,
stop:0 rgb(66, 73, 78),
stop:1 rgb(54, 49, 53));
}
QComboBox:focus {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.8,
stop:0 rgb(61, 68, 73),
stop:1 rgb(39, 44, 48));
}
QComboBox::down-arrow { width: 0px; image: url(:None); }
QComboBox::drop-down { border: none; background: none;}
""")
我在列表视图中根本看不到我的 qss。 感谢您的帮助。
我认为您的意思是
QAbstractItemView
而不是QItemView
,如果您的意图只是对其应用样式表,则无需实际构建 QListView,Combobox 已经内置了一个。
相反,您可以将
QAbstractItemView
样式嵌套在 qss 中的 QComboBox
父级中。例如:
comboBoxStyleSheet = """
QComboBox {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.8,
stop:0 rgb(71, 78, 83),
stop:1 rgb(49, 54, 58));
border: none;
border-radius: 19px;
color: #f2f2f2;
font-size: 14px;
padding-left:16px;
}
QComboBox:hover {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.8,
stop:0 rgb(66, 73, 78),
stop:1 rgb(54, 49, 53));
}
QComboBox:focus {
background-color: qlineargradient(x1:0, y1:0, x2:1, y2:0.8,
stop:0 rgb(61, 68, 73),
stop:1 rgb(39, 44, 48));
}
QComboBox::down-arrow {
width: 0px;
image: url(:None);
}
QComboBox::drop-down {
border: none;
background: none;
}
QComboBox QAbstractItemView::item {
min-height: 35px;
min-width: 50px;
outline: none;
}
QComboBox QAbstractItemView::item:selected {
color: black;
background: lightgray;
}
"""
self.b2 = QComboBox(self)
self.b2.setView(QListView())
self.b2.addItems(['UX Research', 'Mobile Design', 'Visual Design','UX/UI Design','Illustration'])
self.b2.setFixedSize(220, 38)
self.b2.move(24, 24)
self.b2.setPlaceholderText("Choose")
self.b2.setStyleSheet(comboBoxStyleSheet)