我无法使QComboBox的下拉列表具有相同的颜色。当我单击组合框时,会出现
我不希望白色边框颜色看起来像是此下拉菜单滚动条的一部分。但是,我不知道这个白色边框属于什么!它是QComboBox的QAbstractScrollArea吗?是QListView吗?是QScrollArea,QScroller还是QScrollBar?我尝试为所有这些属性设置背景颜色/边框颜色,但无济于事。以下是我的应用程序的精简版,因此您可以将其复制并粘贴到python中并运行它(不幸的是,我真的无法将其进一步缩短,抱歉!!)
import sys
import os
import urllib.request
from PyQt5.QtWidgets import QApplication, QComboBox, QMainWindow, QVBoxLayout, QWidget
from PyQt5.QtCore import QSize
from PyQt5.QtGui import QPixmap, QIcon
class MainWindow(QMainWindow):
def __init__(self, app):
super().__init__()
self.vlayout = QVBoxLayout()
self.main_widget = QWidget()
self.init_combobox()
self.main_widget.setLayout(self.vlayout)
self.setCentralWidget(self.main_widget)
self.show()
def init_combobox(self):
data_solid = urllib.request.urlopen('https://i.imgur.com/fbrdSkv.png').read()
pixmap_solid = QPixmap()
pixmap_solid.loadFromData(data_solid)
data_dashed = urllib.request.urlopen('https://i.imgur.com/gI9oHKm.png').read()
pixmap_dashed = QPixmap()
pixmap_dashed.loadFromData(data_dashed)
data_dotted = urllib.request.urlopen('https://i.imgur.com/AAu4TrX.png').read()
pixmap_dotted = QPixmap()
pixmap_dotted.loadFromData(data_dotted)
cbox = QComboBox()
cbox.setObjectName('linestylecbox')
cbox.setFixedSize(75, 25)
cbox.addItem(QIcon(pixmap_solid), '')
cbox.addItem(QIcon(pixmap_dashed), '')
cbox.addItem(QIcon(pixmap_dotted), '')
cbox.setIconSize(QSize(75, 25))
cbox.setContentsMargins(0, 0, 50, 0)
cbox.setStyleSheet('''
QComboBox#linestylecbox
{
background-color: black;
color: black;
font: 10px Lucida Sans;
border: 0px solid black;
margin: 0px;
}
QComboBox#linestylecbox::drop-down
{
border: 0px;
border-top: 0px;
border-color: black;
background-color: black;
font: 10px Lucida Sans;
}
QComboBox#linestylecbox QListView
{
background-color: black;
color: black;
}
''')
self.vlayout.addWidget(cbox)
if __name__ == '__main__':
app = QApplication(sys.argv)
mw = MainWindow(app)
sys.exit(app.exec_())