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. Popup menu
Qt 6.11 is out! See what's new in the release blog

Popup menu

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 6 Posters 1.8k 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.
  • O Offline
    O Offline
    Oumayma
    wrote on last edited by
    #1

    Hello, I am using mousePressEvent to display an option from my menu, I have a condition where if I press the right button of my mouse, one of the options that I have in my menu is displayed. My problem has been that the menu is displayed in the middle of the screen and I would like it to be displayed below the menu option that I am displayed.
    thanks.

    void MainWindow:: mousePressEvent (QMouseEvent * evento)

    {
    if(evento->buttons() & Qt::RightButton){
    QPoint point = ui->menuArchivo->pos();
    ui->menuArchivo->popup(point);
    }
    }

    Ketan__Patel__0011K 1 Reply Last reply
    0
    • O Oumayma

      Hello, I am using mousePressEvent to display an option from my menu, I have a condition where if I press the right button of my mouse, one of the options that I have in my menu is displayed. My problem has been that the menu is displayed in the middle of the screen and I would like it to be displayed below the menu option that I am displayed.
      thanks.

      void MainWindow:: mousePressEvent (QMouseEvent * evento)

      {
      if(evento->buttons() & Qt::RightButton){
      QPoint point = ui->menuArchivo->pos();
      ui->menuArchivo->popup(point);
      }
      }

      Ketan__Patel__0011K Offline
      Ketan__Patel__0011K Offline
      Ketan__Patel__0011
      wrote on last edited by
      #2

      @Oumayma

      you want to display the Popup menu at any position of the screen Right ?

      O 1 Reply Last reply
      0
      • Ketan__Patel__0011K Ketan__Patel__0011

        @Oumayma

        you want to display the Popup menu at any position of the screen Right ?

        O Offline
        O Offline
        Oumayma
        wrote on last edited by
        #3

        @Ketan__Patel__0011
        no, I want the actions within a qmenu to appear below the menu option in question

        I get this:

        Captura de pantalla (8).png

        I need this:

        Captura de pantalla (9).png

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

          Hi,

          From your drawing it seems you want a normal menu to be shown as when you left click on a menu.

          Do you mean you only want to change one menu entry when right clicking ?

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

          O 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            From your drawing it seems you want a normal menu to be shown as when you left click on a menu.

            Do you mean you only want to change one menu entry when right clicking ?

            O Offline
            O Offline
            Oumayma
            wrote on last edited by
            #5

            @SGaist Hello, I want that when I press the right click anywhere on my screen it appears the same as the second image.

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

              From your second image it seems you have clicked on the Archivo menu. Is that the effect you want ?

              Note that this behaviour is going to disturb your users. If I right click somewhere on an application I certainly would think it's a bug that a menu opens like that rather than a contextual menu under the mouse pointer.

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

              O 1 Reply Last reply
              1
              • SGaistS SGaist

                From your second image it seems you have clicked on the Archivo menu. Is that the effect you want ?

                Note that this behaviour is going to disturb your users. If I right click somewhere on an application I certainly would think it's a bug that a menu opens like that rather than a contextual menu under the mouse pointer.

                O Offline
                O Offline
                Oumayma
                wrote on last edited by
                #7

                @SGaist yes that's the effect i want.

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

                  What if you call the menu's popup exec method with no parameters ?

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

                  O 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    What if you call the menu's popup exec method with no parameters ?

                    O Offline
                    O Offline
                    Oumayma
                    wrote on last edited by
                    #9

                    @SGaist what do you mean, can you explain me please?

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

                      Sorry I meant exec.

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

                      1 Reply Last reply
                      0
                      • O Offline
                        O Offline
                        Oumayma
                        wrote on last edited by
                        #11

                        When using the exec method I do not achieve the expected result, ¿ there is another method that can help me?.

                        thanks

                        1 Reply Last reply
                        0
                        • nageshN Offline
                          nageshN Offline
                          nagesh
                          wrote on last edited by
                          #12

                          @Oumayma Did you try ui->menuArchivo->exec() method as suggested by @SGaist

                          When using the exec method I do not achieve the expected result
                          

                          What behavior that exec() is showing when used?

                          O 1 Reply Last reply
                          0
                          • nageshN nagesh

                            @Oumayma Did you try ui->menuArchivo->exec() method as suggested by @SGaist

                            When using the exec method I do not achieve the expected result
                            

                            What behavior that exec() is showing when used?

                            O Offline
                            O Offline
                            Oumayma
                            wrote on last edited by
                            #13

                            @nagesh 488b63e3-72b1-4591-be18-ecdd06cfaed5-image.png

                            JonBJ 1 Reply Last reply
                            0
                            • Christian EhrlicherC Offline
                              Christian EhrlicherC Offline
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              You have to pass the correct global coordinates for the popup to appear as stated in the documentation: Pops up the menu so that the action action will be at the specified global position p. To translate a widget's local coordinates into global coordinates, use QWidget::mapToGlobal().

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              0
                              • O Oumayma

                                @nagesh 488b63e3-72b1-4591-be18-ecdd06cfaed5-image.png

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by
                                #15

                                @Oumayma
                                You now have at least 3 separate questions going on exactly this topic.

                                It is not nice to make different people respond to the same issue in different threads. It wastes/duplicates their efforts. Is it not reasonable to limit yourself to just one topic for this?

                                Christian EhrlicherC 1 Reply Last reply
                                0
                                • JonBJ JonB

                                  @Oumayma
                                  You now have at least 3 separate questions going on exactly this topic.

                                  It is not nice to make different people respond to the same issue in different threads. It wastes/duplicates their efforts. Is it not reasonable to limit yourself to just one topic for this?

                                  Christian EhrlicherC Offline
                                  Christian EhrlicherC Offline
                                  Christian Ehrlicher
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @JonB I did not notice it before answering this one. Therefore I close this now because it's an exact duplicate of https://forum.qt.io/topic/125327/qmenu-popup/

                                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                  Visit the Qt Academy at https://academy.qt.io/catalog

                                  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