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. QComboBox popup menu
Qt 6.11 is out! See what's new in the release blog

QComboBox popup menu

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.6k 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.
  • HunterMetcalfeH Offline
    HunterMetcalfeH Offline
    HunterMetcalfe
    wrote on last edited by
    #1

    Curious, has anyone ever created their own ComboBox class inherited from QComboBox where you can emit a signal when the popmenu has been clicked and, of course, emit a signal once it is closed? It's just when the popup menu is clicked, the main ComboBox loses focus. I'm trying to capture the event of the popup, but I've never really worked with Event Filtering in QT. Any help would be most appreciated.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      No need for event filtering just reimplement showPopup and hidePopup

      #ifndef TESTCOMBO_H
      #define TESTCOMBO_H
      
      #include <QComboBox>
      
      class TestCombo : public QComboBox
      {
          Q_OBJECT
      public:
          TestCombo(QWidget* parent=nullptr):QComboBox(parent){}
          virtual ~TestCombo()=default;
          virtual void hidePopup() override{
              emit menuHidden();
              QComboBox::hidePopup();
          }
          virtual void showPopup() override{
              emit menuPopped();
              QComboBox::showPopup();
          }
      signals:
          void menuPopped();
          void menuHidden();
      };
      
      #endif // TESTCOMBO_H
      

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      HunterMetcalfeH 1 Reply Last reply
      1
      • VRoninV VRonin

        No need for event filtering just reimplement showPopup and hidePopup

        #ifndef TESTCOMBO_H
        #define TESTCOMBO_H
        
        #include <QComboBox>
        
        class TestCombo : public QComboBox
        {
            Q_OBJECT
        public:
            TestCombo(QWidget* parent=nullptr):QComboBox(parent){}
            virtual ~TestCombo()=default;
            virtual void hidePopup() override{
                emit menuHidden();
                QComboBox::hidePopup();
            }
            virtual void showPopup() override{
                emit menuPopped();
                QComboBox::showPopup();
            }
        signals:
            void menuPopped();
            void menuHidden();
        };
        
        #endif // TESTCOMBO_H
        
        HunterMetcalfeH Offline
        HunterMetcalfeH Offline
        HunterMetcalfe
        wrote on last edited by
        #3

        @VRonin Thank you so much! This is exactly what I was looking for. I appreciate your help!

        1 Reply Last reply
        0

        • Login

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