Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to set QStyle::SH_ComboBox_Popup to false?
QtWS25 Last Chance

How to set QStyle::SH_ComboBox_Popup to false?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qstylecomboboxfusion
6 Posts 2 Posters 995 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    CJha
    wrote on 11 Aug 2021, 14:37 last edited by CJha 8 Nov 2021, 14:39
    #1

    I am using fusion style on windows. In this style the QComboBox is ignoring the maxVisibleItems 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 no setStyleHint() function in QStyle class. Is there another way to get around this weird issue?

    R 1 Reply Last reply 11 Aug 2021, 14:53
    0
    • C CJha
      11 Aug 2021, 14:37

      I am using fusion style on windows. In this style the QComboBox is ignoring the maxVisibleItems 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 no setStyleHint() function in QStyle class. Is there another way to get around this weird issue?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 11 Aug 2021, 14:53 last edited by
      #2

      @CJha
      have you already seen the QProxyStyle class?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      C 1 Reply Last reply 11 Aug 2021, 14:58
      1
      • R raven-worx
        11 Aug 2021, 14:53

        @CJha
        have you already seen the QProxyStyle class?

        C Offline
        C Offline
        CJha
        wrote on 11 Aug 2021, 14:58 last edited by
        #3

        @raven-worx Yes, but I am unable to understand how to override this in QProxyStyle class.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          CJha
          wrote on 11 Aug 2021, 15:03 last edited by
          #4

          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);
              }
          };
          
          R 1 Reply Last reply 11 Aug 2021, 15:16
          0
          • C CJha
            11 Aug 2021, 15:03

            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);
                }
            };
            
            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 11 Aug 2021, 15:16 last edited by
            #5

            @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()

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            C 1 Reply Last reply 11 Aug 2021, 15:30
            1
            • R raven-worx
              11 Aug 2021, 15:16

              @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()

              C Offline
              C Offline
              CJha
              wrote on 11 Aug 2021, 15:30 last edited by
              #6

              @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 replaced QStyle::SH_UnderlineShortcut with QStyle::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.

              1 Reply Last reply
              1

              4/6

              11 Aug 2021, 15:03

              • Login

              • Login or register to search.
              4 out of 6
              • First post
                4/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved