大家可能会遇到自己的 Qt 界面程序中 QComboBox 部件在 Linux 下点击下拉后不出现滚动条(当数据项比较多时),而是一股脑的占满了纵向整个屏幕:
但同一个程序在 Windows 下却能得到我们想要的效果:
这其实和 QComboBox 的 maxVisibleItems 属性有关,该属性通过代码和 designer 都可以设置:
可以仅仅设置了该属性值还不够,Qt6.1.1官方手手册对该属性描述如下:
maxVisibleItems : int
This property holds the maximum allowed size on screen of the combo box, measured in items
By default, this property has a value of 10.
Note: This property is ignored for non-editable comboboxes in styles that returns true for QStyle::SH_ComboBox_Popup such as