且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PyQt QComboBox 设置下拉菜单中可见项目的数量

更新时间:2022-12-12 16:56:23

根据文档:

对于在 `QStyle::SH_ComboBox_Popup 如 Mac 风格或 Gtk+ 风格.

The property maxVisibleItems is ignored for non-editable comboboxes in styles that returns true for `QStyle::SH_ComboBox_Popup such as the Mac style or the Gtk+ Style.

并且您可以使用样式表覆盖 SH_ComboBox_Popup 样式提示:

And you can override that SH_ComboBox_Popup style hint with a style sheet:

combo.setStyleSheet("QComboBox { combobox-popup: 0; }");