QComboBox调整下拉宽度
QComboBox adjust drop down width
不知道为什么我不能让它工作,所以也许你们中的一个能看到我的错误...:[=11=]
combo_type = QComboBox()
combo_type.setMaximumWidth(50)
combo_type.addItems(["TEsst1111","TEsst11111111111111","TEsst1111111111111111111111111"])
combo_type.setStyleSheet('''*
QComboBox QAbstractItemView::item
{
min-width: 6000px;
}
''')
这个想法是 UI 中的小部件具有 50 宽度,但是当下拉并打开时我可以阅读列表,遗憾的是样式表覆盖不会更改下拉宽度使其 50 且不可读。 ..
谢谢。
已排序...这是命名错误。正确答案贴在下面。
combo_type.setStyleSheet('''*
QComboBox QAbstractItemView
{
min-width: 150px;
}
''')
使用 QListView
:
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;}"
''')
不知道为什么我不能让它工作,所以也许你们中的一个能看到我的错误...:[=11=]
combo_type = QComboBox()
combo_type.setMaximumWidth(50)
combo_type.addItems(["TEsst1111","TEsst11111111111111","TEsst1111111111111111111111111"])
combo_type.setStyleSheet('''*
QComboBox QAbstractItemView::item
{
min-width: 6000px;
}
''')
这个想法是 UI 中的小部件具有 50 宽度,但是当下拉并打开时我可以阅读列表,遗憾的是样式表覆盖不会更改下拉宽度使其 50 且不可读。 ..
谢谢。
已排序...这是命名错误。正确答案贴在下面。
combo_type.setStyleSheet('''*
QComboBox QAbstractItemView
{
min-width: 150px;
}
''')
使用 QListView
:
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;}"
''')