Which Signal is related to click or open QComboBox?



  • I need to when user click or open QComboBox "slot self.materialsInstance.addToComboBox_Insert" will be emitted.But i don't know related Signal...!

    Notes: My QComboBox is empty.

    My question is, What's related signal for open or click on QComboBox?


  • Moderators

    If your combox is empty no signal will be emitted.
    But you can "installEventFilter":http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#installEventFilter for your combobox and reimplement "eventfilter":http://qt-project.org/doc/qt-4.8/eventsandfilters.html#event-filters and intercept the event you desire viz. MousePress or MouseRelease in your case and do there whatever is needed.



  • class KeyPressEater : public QObject
    {
    Q_OBJECT
    ...

    protected:
    bool eventFilter(QObject *obj, QEvent *event);
    };

    bool KeyPressEater::eventFilter(QObject *obj, QEvent *event)
    {
    if (event->type() == QEvent::KeyPress) {
    QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
    qDebug("Ate key press %d", keyEvent->key());
    return true;
    } else {
    // standard event processing
    return QObject::eventFilter(obj, event);
    }
    }

    KeyPressEater *keyPressEater = new KeyPressEater(this);
    QPushButton *pushButton = new QPushButton(this);
    QListView *listView = new QListView(this);

    pushButton->installEventFilter(keyPressEater);
    listView->installEventFilter(keyPressEater);



  • A bit late but for everyone who finds this post in a quest to get this question answered:
    An alternative is to overload the showPopup method:

    #include <QComboBox>

    class CPortsComboBox : public QComboBox
    {
    Q_OBJECT
    public:
    explicit CPortsComboBox(QWidget *parent = 0);
    virtual ~CPortsComboBox();

    public:
    virtual void showPopup()
    {
    while (count() > 0) { removeItem(0); }
    addItem("hello");
    addItem("World"):
    QComboBox::showPopup();
    }
    };


Log in to reply
 

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