QComboBox popup menu



  • 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.



  • 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
    


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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.