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. Qmenu aboutToShow do not freeze the program while it is open
Forum Updated to NodeBB v4.3 + New Features

Qmenu aboutToShow do not freeze the program while it is open

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 3 Posters 1.0k Views 2 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.
  • KaguroK Offline
    KaguroK Offline
    Kaguro
    wrote on last edited by
    #1

    Hi Guys!
    Sorry again if its a rally lame question.
    I have some QPushbuttons with hover effect (change the background to yellow) and these buttons have Qmenus (button->setMenu(Menu1)).
    When i click one of them, the background turns yellow and perfectly drop down the menu items. Til it is open the background is freez, so i move the cursor above another button, not turn into yellow, but when i click on it (the opened menu is perfectly close and the menubutton turn into the default color) the menu is perfectly open but the menuPushbutton not turn into yellow.

    So what i would like to achive when a menu is opened and i move to another buttonmenu turn into yellow with hover effect, and when i clicked to another the new one turn into yellow and drop the menu as well.

    I see its a pretty bad attempt but i dont have any other solutions :(

    Any advice? wehere is my mistakes? Ty guys!

    1 Reply Last reply
    0
    • KaguroK Kaguro

      @mrjj @SGaist So the correct question: How can i create a menu bar with Pushbuttons (and the QPushButtons have menu)?

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #11

      @Kaguro

      Hi
      Im not sure its possible to make it work. Its about toplevel widgets and we cannot change that for QMenu
      as then it stop working.

      The best work around in my opinion is to use an event filter to make it close if the user moves the mouse outside the menu

      .. somewhere...
          menuSettings = new QMenu(this); // menuSettings must be a member
          menuSettings->addAction("Config CAMS");
          menuSettings->addAction("Alarms");
          menuSettings->addAction("Storage");
          menuSettings->addAction("Plano");
          menuSettings->addAction("Advance");
          menuSettings->addAction("Report");
          ui->pushButton->setMenu(menuSettings);
      
          menuSettings->installEventFilter(this); //  INSTALL event filer
      }
      
      
      bool MainWindow::eventFilter(QObject *obj, QEvent *event)  // the filter
      {
          if (obj == menuSettings && event->type() == QEvent::Leave) {
          if (menuSettings)
            menuSettings->close();
         }
          return false;
      }
      

      alt text

      KaguroK 1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Yellow not being a usual color, is it part of your desktop color scheme ? Custom to your application ? Are you using a stylesheet ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        KaguroK 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Yellow not being a usual color, is it part of your desktop color scheme ? Custom to your application ? Are you using a stylesheet ?

          KaguroK Offline
          KaguroK Offline
          Kaguro
          wrote on last edited by Kaguro
          #3

          @SGaist the color is not important. The fact that freez the bacground (until i don't choose a menu item) and not activate another hover effect when a qmenu is open is the question.

          Okay sorry for my bad english. So i illustrate with some pictures (the red point is my cursor)
          1: i move with cursor above my button (its okay)
          1.png
          2: i click on it and drop down the menu and i move the cursor hover the menu items (its okay)
          2.png
          3: i dont click, just move hover the "Pre set" button... and its not okay, couse the hover effect is not activated, but i want to activate hover effect (so the button's background not turn into yellow)
          3.png
          4: and when i click on it (the "pre set" button), not turn into yellow, but i want to turn it to yellow. the menu items works well here too.
          4.png

          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #4

            Hi
            You can try using
            https://doc.qt.io/qt-5/qmenu.html#popup
            instead of
            https://doc.qt.io/qt-5/qmenu.html#exec
            to show the dropdown menu.

            The reason for the hover event is not coming for other widgets when the menu is open could be due to the use
            of exec() or that its considered a toplevel window and hence also steals the events.

            KaguroK 1 Reply Last reply
            0
            • mrjjM mrjj

              Hi
              You can try using
              https://doc.qt.io/qt-5/qmenu.html#popup
              instead of
              https://doc.qt.io/qt-5/qmenu.html#exec
              to show the dropdown menu.

              The reason for the hover event is not coming for other widgets when the menu is open could be due to the use
              of exec() or that its considered a toplevel window and hence also steals the events.

              KaguroK Offline
              KaguroK Offline
              Kaguro
              wrote on last edited by
              #5

              @mrjj Hello!
              I use aboutToShow not exec. because i wanted to copy the menubutton size (for all menuitem).
              But if i tried with the popup the issue is the same :( And the menu items size not correct.

              mrjjM 1 Reply Last reply
              0
              • KaguroK Kaguro

                @mrjj Hello!
                I use aboutToShow not exec. because i wanted to copy the menubutton size (for all menuitem).
                But if i tried with the popup the issue is the same :( And the menu items size not correct.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #6

                @Kaguro
                Hi
                Ok so even if you use popup to show the dropdown menu, the
                other widgets still dont get the hover event ?

                aboutToShow is just a signal to say menu is about to be shown.
                Its not really related to your current issue.

                I think the main issue is that QMenu takes all events when open.
                Not 100% sure why yet.

                KaguroK 2 Replies Last reply
                0
                • mrjjM mrjj

                  @Kaguro
                  Hi
                  Ok so even if you use popup to show the dropdown menu, the
                  other widgets still dont get the hover event ?

                  aboutToShow is just a signal to say menu is about to be shown.
                  Its not really related to your current issue.

                  I think the main issue is that QMenu takes all events when open.
                  Not 100% sure why yet.

                  KaguroK Offline
                  KaguroK Offline
                  Kaguro
                  wrote on last edited by
                  #7

                  @mrjj Yes! If i used popup the other widgets still dont get the hover event. Everything else is "freeze".
                  Yeah you are right the abouttoshow is not related in this problem.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #8

                    So if I understand correctly you would like to have your set of buttons behave more or less like a menu bar ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    KaguroK 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      So if I understand correctly you would like to have your set of buttons behave more or less like a menu bar ?

                      KaguroK Offline
                      KaguroK Offline
                      Kaguro
                      wrote on last edited by
                      #9

                      @SGaist Yes! You are right! Like the menubar

                      1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @Kaguro
                        Hi
                        Ok so even if you use popup to show the dropdown menu, the
                        other widgets still dont get the hover event ?

                        aboutToShow is just a signal to say menu is about to be shown.
                        Its not really related to your current issue.

                        I think the main issue is that QMenu takes all events when open.
                        Not 100% sure why yet.

                        KaguroK Offline
                        KaguroK Offline
                        Kaguro
                        wrote on last edited by
                        #10

                        @mrjj @SGaist So the correct question: How can i create a menu bar with Pushbuttons (and the QPushButtons have menu)?

                        mrjjM 1 Reply Last reply
                        0
                        • KaguroK Kaguro

                          @mrjj @SGaist So the correct question: How can i create a menu bar with Pushbuttons (and the QPushButtons have menu)?

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #11

                          @Kaguro

                          Hi
                          Im not sure its possible to make it work. Its about toplevel widgets and we cannot change that for QMenu
                          as then it stop working.

                          The best work around in my opinion is to use an event filter to make it close if the user moves the mouse outside the menu

                          .. somewhere...
                              menuSettings = new QMenu(this); // menuSettings must be a member
                              menuSettings->addAction("Config CAMS");
                              menuSettings->addAction("Alarms");
                              menuSettings->addAction("Storage");
                              menuSettings->addAction("Plano");
                              menuSettings->addAction("Advance");
                              menuSettings->addAction("Report");
                              ui->pushButton->setMenu(menuSettings);
                          
                              menuSettings->installEventFilter(this); //  INSTALL event filer
                          }
                          
                          
                          bool MainWindow::eventFilter(QObject *obj, QEvent *event)  // the filter
                          {
                              if (obj == menuSettings && event->type() == QEvent::Leave) {
                              if (menuSettings)
                                menuSettings->close();
                             }
                              return false;
                          }
                          

                          alt text

                          KaguroK 1 Reply Last reply
                          3
                          • mrjjM mrjj

                            @Kaguro

                            Hi
                            Im not sure its possible to make it work. Its about toplevel widgets and we cannot change that for QMenu
                            as then it stop working.

                            The best work around in my opinion is to use an event filter to make it close if the user moves the mouse outside the menu

                            .. somewhere...
                                menuSettings = new QMenu(this); // menuSettings must be a member
                                menuSettings->addAction("Config CAMS");
                                menuSettings->addAction("Alarms");
                                menuSettings->addAction("Storage");
                                menuSettings->addAction("Plano");
                                menuSettings->addAction("Advance");
                                menuSettings->addAction("Report");
                                ui->pushButton->setMenu(menuSettings);
                            
                                menuSettings->installEventFilter(this); //  INSTALL event filer
                            }
                            
                            
                            bool MainWindow::eventFilter(QObject *obj, QEvent *event)  // the filter
                            {
                                if (obj == menuSettings && event->type() == QEvent::Leave) {
                                if (menuSettings)
                                  menuSettings->close();
                               }
                                return false;
                            }
                            

                            alt text

                            KaguroK Offline
                            KaguroK Offline
                            Kaguro
                            wrote on last edited by Kaguro
                            #12

                            @mrjj Oh yeah! This is it and works! :D Many many thanks my hero!

                            1 Reply Last reply
                            1

                            • Login

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