How to set QStyle::SH_ComboBox_Popup to false?
-
I am using
fusion
style on windows. In this style theQComboBox
is ignoring themaxVisibleItems
property: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.
I have around 150 entries in my combo-box and when I click on it, the combo-box expands from top to bottom of my monitor. How can I set the
QStyle::SH_ComboBox_Popup
property to false? There is nosetStyleHint()
function inQStyle
class. Is there another way to get around this weird issue? -
@CJha
have you already seen the QProxyStyle class? -
@raven-worx Yes, but I am unable to understand how to override this in
QProxyStyle
class. -
Thanks to @raven-worx I figured it out using
QProxyStyle
, here is my code:class MyProxyStyle : public QProxyStyle { public: int styleHint(StyleHint hint, const QStyleOption* option = nullptr, const QWidget* widget = nullptr, QStyleHintReturn* returnData = nullptr) const override { if(hint == QStyle::SH_ComboBox_Popup) return 0; return QProxyStyle::styleHint(hint, option, widget, returnData); } };
-
@CJha
yes, where is the problem exactly?
But i am anyway not sure if you get what you want just by simply switching a flag.Another approach would be to subclass QComboBox and overrride the virtual showPopup() method.
In there call the base class implementation and afterwards resize and reposition the popup window.You can get the popu window with
comboBox->view()->window()
-
@raven-worx For me, it seems as it is working. The above code is actually taken from
ProxyStyle
web page from Qt's website, I just replacedQStyle::SH_UnderlineShortcut
withQStyle::SH_ComboBox_Popup
. So, I think it is a good approach.Subclassing
QComboBox
would become quite cumbersome as I will have to promote all the combo boxes in my UI to the subclass.