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. Click on drop-down list of QComboBox
QtWS25 Last Chance

Click on drop-down list of QComboBox

Scheduled Pinned Locked Moved Solved General and Desktop
comboboxmousepressevent
9 Posts 2 Posters 8.7k Views
  • 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
    Maluna34
    wrote on last edited by Maluna34
    #1

    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-worxR 1 Reply Last reply
    0
    • M 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-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @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
      2
      • raven-worxR raven-worx

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

        M Offline
        M Offline
        Maluna34
        wrote on last edited by
        #3

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

        It does not work. :(

        raven-worxR 1 Reply Last reply
        0
        • M Maluna34

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

          It does not work. :(

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          @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
          0
          • raven-worxR raven-worx

            @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?

            M Offline
            M Offline
            Maluna34
            wrote on last edited by Maluna34
            #5

            @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-worxR 1 Reply Last reply
            0
            • M 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-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #6

              @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
              0
              • raven-worxR 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);
                    }
                
                M Offline
                M Offline
                Maluna34
                wrote on last edited by
                #7

                @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-worxR 1 Reply Last reply
                0
                • M Maluna34

                  @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-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  @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
                  0
                  • raven-worxR raven-worx

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

                    M Offline
                    M Offline
                    Maluna34
                    wrote on last edited by
                    #9

                    @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
                    0

                    • Login

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