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 popup
Forum Updated to NodeBB v4.3 + New Features

Qmenu popup

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 5 Posters 1.7k 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 Oumayma
    #1

    ¿What is the method that displays the menu in the position that appears in the image when you click on it?

    a7756acd-cca7-469f-9df2-93010653a31b-image.png

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

      @Oumayma question not clearly understood.

      https://doc.qt.io/qt-5/qmenu.html

      is it about QMenu::addAction ? or QAction *QMenu::exec()?

      O 1 Reply Last reply
      0
      • nageshN nagesh

        @Oumayma question not clearly understood.

        https://doc.qt.io/qt-5/qmenu.html

        is it about QMenu::addAction ? or QAction *QMenu::exec()?

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

        @nagesh I explain the question: when you click on a menu, its actions are displayed as shown in the image, I would like to know what method makes that happen.

        JonBJ 1 Reply Last reply
        0
        • O Oumayma

          @nagesh I explain the question: when you click on a menu, its actions are displayed as shown in the image, I would like to know what method makes that happen.

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

          @Oumayma
          QMenu::exec().

          O 1 Reply Last reply
          0
          • JonBJ JonB

            @Oumayma
            QMenu::exec().

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

            @JonB when using this method it displays the menu in another position.

            e243c427-18aa-444a-bd03-f5f29cbeb9ba-image.png

            JonBJ 1 Reply Last reply
            0
            • O Oumayma

              @JonB when using this method it displays the menu in another position.

              e243c427-18aa-444a-bd03-f5f29cbeb9ba-image.png

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

              @Oumayma
              Read https://doc.qt.io/qt-5/qmenu.html#exec

              This is equivalent to exec(pos()).

              In most situations you'll want to specify the position yourself, for example, the current mouse position:

              exec(QCursor::pos());

              or aligned to a widget:

              exec(somewidget.mapToGlobal(QPoint(0,0)));

              or in reaction to a QMouseEvent *e:

              exec(e->globalPos());

              O 1 Reply Last reply
              0
              • JonBJ JonB

                @Oumayma
                Read https://doc.qt.io/qt-5/qmenu.html#exec

                This is equivalent to exec(pos()).

                In most situations you'll want to specify the position yourself, for example, the current mouse position:

                exec(QCursor::pos());

                or aligned to a widget:

                exec(somewidget.mapToGlobal(QPoint(0,0)));

                or in reaction to a QMouseEvent *e:

                exec(e->globalPos());

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

                @JonB I have already tried the options that it indicates to me, what I want is to know from where to get the position in which the menu is displayed as it does in the first image.
                thanks.

                JonBJ 1 Reply Last reply
                0
                • M Offline
                  M Offline
                  macfanpl
                  wrote on last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • O Oumayma

                    @JonB I have already tried the options that it indicates to me, what I want is to know from where to get the position in which the menu is displayed as it does in the first image.
                    thanks.

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

                    @Oumayma
                    I would guess the (bottom left) position of the item the mouse clicks on on the menu bar?

                    O 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Oumayma
                      I would guess the (bottom left) position of the item the mouse clicks on on the menu bar?

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

                      @JonB ¿There is any method that returns me the lower left position of a QMenu?

                      O 1 Reply Last reply
                      0
                      • O Oumayma

                        @JonB ¿There is any method that returns me the lower left position of a QMenu?

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

                        @Oumayma
                        I have added this line of code:
                        ui->menuArchivo->exec(QMenu(ui->menuArchivo).rect().bottomLeft());
                        this is the result:
                        b7f8c1f7-ded9-4f1a-a62d-9a2d0465ed98-image.png

                        JonBJ Pl45m4P 2 Replies Last reply
                        0
                        • O Oumayma

                          @Oumayma
                          I have added this line of code:
                          ui->menuArchivo->exec(QMenu(ui->menuArchivo).rect().bottomLeft());
                          this is the result:
                          b7f8c1f7-ded9-4f1a-a62d-9a2d0465ed98-image.png

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

                          @Oumayma
                          So you need to move it down a bit, for whatever reason?

                          Before you spend too long on this. I seem to remember quite a while ago that someone asked to be able to access the individual menu actions like this for their own purpose. And I have a feeling that he never got an answer as to how to access the correct horizontal position for each of the items in the menu (your Edicion etc.) Even if you can the vertical position correct, you had better make sure you can get the horizontal position of each item after the first, left-most, else you won't get anywhere....

                          I may be wrong. After all, the Qt code must be able to get that right (maybe you should look at its source code), so perhaps I misremember and you can get the correct horizontal position, but you should check.

                          1 Reply Last reply
                          0
                          • O Oumayma

                            @Oumayma
                            I have added this line of code:
                            ui->menuArchivo->exec(QMenu(ui->menuArchivo).rect().bottomLeft());
                            this is the result:
                            b7f8c1f7-ded9-4f1a-a62d-9a2d0465ed98-image.png

                            Pl45m4P Offline
                            Pl45m4P Offline
                            Pl45m4
                            wrote on last edited by Pl45m4
                            #13

                            @Oumayma said in Qmenu popup:

                            @Oumayma
                            I have added this line of code:
                            ui->menuArchivo->exec(QMenu(ui->menuArchivo).rect().bottomLeft());
                            this is the result:
                            b7f8c1f7-ded9-4f1a-a62d-9a2d0465ed98-image.png

                            Map the point to correct coordinate system.
                            The rect returns the bottomLeft in menuArchivo coordinates (probably something like 0/20). But exec uses global/your MainWindow's coordinates. This is why your popup starts at (0/20) but from the top of your MainWindow.
                            So try to map your bottomLeft to parent or global (with ui->menuArchivo->mapToGlobal(ui->menuArchivo->rect().bottomLeft())) <- not tested. Play around until you get a satisfying result.


                            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                            ~E. W. Dijkstra

                            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