Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Which Signal is related to click or open QComboBox?
Qt 6.12 LTS is out! See what's new in the release blog

Which Signal is related to click or open QComboBox?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 13.4k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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.

      157

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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);

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Pieter Bijleveld
          wrote on last edited by
          #4

          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();
          }
          };

          1 Reply Last reply
          2

          • Login

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