Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Click on drop-down list of QComboBox

    General and Desktop
    combobox mousepressevent
    2
    9
    6587
    Loading More Posts
    • 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
      Maluna34 last edited by Maluna34

      Hello ! :)

      I currently have a QComboBox in a QGraphicsScene and I need it to detect clicks. To see if there is a widget in the clicked position, I use :

      void BlockScene::mousePressEvent(QMouseEvent *event)
      {
          if (itemAt(event->pos()) != m_widgetItem)
          {
              // ...
          }
      }
      

      This works well for different widgets except for combo boxes where it only takes into account the original widget and not the drop-down list that appears after a first click.

      To know if it came from the scene or not, I tested also by redefining mousePressEvent of the class QComboBox and same problem: it is called only when clicking on the initial widget. :(

      Is there a way to get the drop-down list ? To detect a click on it ? Ideas ?

      Thanks ! ;)

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Maluna34 last edited by

        @Maluna34
        install an event-filter on the combo box's view and inspect the mouse events.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        M 1 Reply Last reply Reply Quote 2
        • M
          Maluna34 @raven-worx last edited by

          @raven-worx
          Do you mean comboBox->view()->installEventFilter(this); or comboBox->installEventFilter(this); ?

          It does not work. :(

          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @Maluna34 last edited by

            @Maluna34 said in Click on drop-down list of QComboBox:

            It does not work. :(

            my glassball is broken, please help me out here.

            Just to make sure: do you know how event-filters work? I guess you didn't overload eventFilter() no?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            M 1 Reply Last reply Reply Quote 0
            • M
              Maluna34 @raven-worx last edited by Maluna34

              @raven-worx
              I did don't worry ! ;) It's just that I'm at work. ^^

              So I tried this :

                  virtual bool eventFilter(QObject *watched, QEvent *event) override
                  {
                      if (watched == m_box)
                      {
                          if (event->type() == QEvent::MouseButtonPress)
                          {
                              qDebug() << "event";
              
                              return QMainWindow::eventFilter(watched, event);
                          }
                      }
                      else
                          return QMainWindow::eventFilter(watched, event);
                  }
              

              With m_box->installEventFilter(this); this is the same as with mousePressEvent, the message only appears when the initial widget is clicked.
              And with m_box->view()->installEventFilter(this); nothing is happening.

              raven-worx 1 Reply Last reply Reply Quote 0
              • raven-worx
                raven-worx Moderators @Maluna34 last edited by raven-worx

                @Maluna34
                install it on the view: comboBox->view()->installEventFilter(this);
                Then you of course in the eventFilter() implementation you also need to check for the view:

                virtual bool eventFilter(QObject *watched, QEvent *event) override
                    {
                        if (watched == m_box->view())
                        {
                            if (event->type() == QEvent::MouseButtonPress)
                            {
                                qDebug() << "event";
                            }
                        }
                
                        return QMainWindow::eventFilter(watched, event);
                    }
                

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                M 1 Reply Last reply Reply Quote 0
                • M
                  Maluna34 @raven-worx last edited by

                  @raven-worx
                  Thanks, I have events on the m_box->view() widget but no click. Here are the kind of events I have on the view :

                  QEvent::Type(Show)
                  QEvent::Type(FocusIn)
                  QEvent::Type(UpdateLater)
                  QEvent::Type(Enter)
                  QEvent::Type(FocusAboutToChange)
                  QEvent::Type(InputMethodQuery)
                  QEvent::Type(ToolTip)
                  QEvent::Type(Leave)
                  QEvent::Type(Enter)
                  QEvent::Type(FocusAboutToChange)
                  QEvent::Type(FocusOut)
                  QEvent::Type(InputMethodQuery)
                  QEvent::Type(Hide)
                  QEvent::Type(Leave)
                  QEvent::Type(Timer)
                  
                  raven-worx 1 Reply Last reply Reply Quote 0
                  • raven-worx
                    raven-worx Moderators @Maluna34 last edited by

                    @Maluna34
                    and when you do the same on view()->viewport()?

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    M 1 Reply Last reply Reply Quote 0
                    • M
                      Maluna34 @raven-worx last edited by

                      @raven-worx
                      It works !!! Thank you !!!

                      Now I just have to see if I can check it into the scene (maybe create a widgetitem for the viewport, I'll see.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post