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. Which Signal is related to click or open QComboBox?
Forum Updated to NodeBB v4.3 + New Features

Which Signal is related to click or open QComboBox?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 12.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.
  • M Offline
    M Offline
    m_pahlevanzadeh
    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
      • M Offline
        M Offline
        mehrdadsilver
        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);

        Mehrdad Abdolghafari, Be silver

        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 Extensions
          • Unsolved