我一直在尝试构建一个自定义组合框,以在绘图GUI中选择线型类型。下拉菜单包含线条样式的预览,例如实线,虚线,虚线。
通过设置组合框的图标大小,我能够调整所选行的大小
mycombobox.setIconSize(QSize(75, 25))
但是,当我单击下拉箭头以显示下拉菜单时,这似乎并不影响QComboBox内的QListView。
上面,您可以看到选定的线型在被选择时可以正确放大,但是在使用下拉菜单时,显示的图标大小不正确。我无法弄清楚如何在不更改图像文件实际大小的情况下更改其大小。
下面是我的自定义QComboBox的代码。我想弄清楚如何更改下拉菜单中图标的大小。我想我必须更改QListView的某些子控件,但是我无法弄清楚。有人知道怎么做这个吗?
self.fitstyle_linestyle_cbox = QComboBox()
self.fitstyle_linestyle_cbox.setObjectName('linestylecbox')
self.fitstyle_linestyle_cbox.setFixedSize(75, 25)
self.linestyle_cbox_item_solid = QPixmap(str(self.dotgui_path) + '/DotGUI/GUIassets/linestyle_edit_solid.png')
self.linestyle_cbox_item_dashed = QPixmap(str(self.dotgui_path) + '/DotGUI/GUIassets/linestyle_edit.png')
self.linestyle_cbox_item_dotted = QPixmap(str(self.dotgui_path) + '/DotGUI/GUIassets/linestyle_edit_dotted.png')
self.fitstyle_linestyle_cbox.addItem(QIcon(self.linestyle_cbox_item_solid), '')
self.fitstyle_linestyle_cbox.addItem(QIcon(self.linestyle_cbox_item_dashed), '')
self.fitstyle_linestyle_cbox.addItem(QIcon(self.linestyle_cbox_item_dotted), '')
self.fitstyle_linestyle_cbox.setIconSize(QSize(75, 25))
self.fitstyle_linestyle_cbox.setStyleSheet('''
QComboBox#linestylecbox
{
background-color: ''' + GlobalVars.color_bkgnd_dark + ''';
color: ''' + GlobalVars.color_text_dark + ''';
font: 10px Lucida Sans;
border: 0px solid ''' + GlobalVars.color_bkgnd_dark + ''';
margin: 0px;
}
QComboBox#linestylecbox::drop-down
{
border: 0px;
border-top: 0px;
border-color: ''' + GlobalVars.color_bkgnd_dark + ''';
background-color: ''' + GlobalVars.color_bkgnd_dark + ''';
font: 10px Lucida Sans;
}
QComboBox#linestylecbox::down-arrow
{
image: url( ''' + str(self.dotgui_path) + '''/DotGUI/GUIassets/down-arrow.png);
width: 10px;
height: 10px;
border: 0px;
}
QListView
{
background-color: ''' + GlobalVars.color_bkgnd_light + ''';
}
''')