QComboBox调整下拉框宽度

2024-10-01 15:35:19 发布

您现在位置:Python中文网/ 问答频道 /正文

不知道为什么我不能让它工作,所以也许你们中的一个可以看到我的错误。。。公司名称:

combo_type = QComboBox()
combo_type.setMaximumWidth(50)
combo_type.addItems(["TEsst1111","TEsst11111111111111","TEsst1111111111111111111111111"])
combo_type.setStyleSheet('''*
    QComboBox QAbstractItemView::item
    {
    min-width: 6000px;
    }
''')

这样做的目的是让widget在UI中有50个宽度,但是当下拉并打开时,我可以阅读列表,遗憾的是样式表覆盖没有改变下拉宽度,使其50和不可读。。。在

谢谢。在


Tags: 名称宽度type错误公司itemcombosetstylesheet
2条回答

使用^{}

combo_type = QComboBox()
combo_type.SizeAdjustPolicy(QComboBox.AdjustToContentsOnFirstShow)

view =  QListView() # creat a ListView
view.setFixedWidth(200) # set the ListView with fixed Width
combo_type.setView(view) # provide the list view to Combobox object

combo_type.setMaximumWidth(500) # will be overwritten by style-sheet
            combo_type.addItems(["TEsst1111","TEsst11111111111111","TEsst1111111111111111111111111"])
combo_type.setStyleSheet('''
QComboBox { max-width: 50px; min-height: 40px;}
QComboBox QAbstractItemView::item { min-height: 150px;}
QListView::item:selected { color: red; background-color: lightgray; min-width: 1000px;}"
''')

排序。。。这是命名错误。正确答案贴在下面。

combo_type.setStyleSheet('''*    
QComboBox QAbstractItemView 
    {
    min-width: 150px;
    }
''')

相关问题 更多 >

    热门问题