Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

set maxVisibleItems property in Fusion Style for QtComboBox(dropdown box)



  • Hi all,

    I am using Qt designer 5.11.1 and building a tool with Python (PyQt5). I saved my GUI in 'Fusion' style. In this, for combobox, there is a property 'maxVisibleItems'. Even though I set this property and limit the dropdown list so that only 5 elements are visible at a time and remaining needs to be scrolled, the combobox still displays all list of items present in the combo box.

    I know the reason and this is the limitation that this property is ignored by non-editable styles as per documentation.

    Note: This property 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.
    

    With this property set, In Fusion style, the application shows all 20 items at once where as in other style, the application shows 5 items at a time . I do not want to change Fusion style. Could someone please help me if I can overcome.

    Few users commented that using

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

    helped them. But it did not work for me. Am I doing anything wrong or is there any different solution.

    How I have tried:

    self.comboBox_2.setStyleSheet("selection-color: rgb(255, 255, 255);\n"
    "background-color: rgb(249, 255, 255);\n"
    "selection-background-color: rgb(53, 107, 255);")
     self.comboBox_2.setObjectName("comboBox_2")
     self.comboBox_2.setStyleSheet("combobox-popup: 0;")
     self.comboBox_2.setMaxVisibleItems(5)
    

    Thanks a lot in advance for sharing your knowledge with your valuable suggestions.


Log in to reply