Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. how to add qaction to the menu in qtoolbar
Forum Updated to NodeBB v4.3 + New Features

how to add qaction to the menu in qtoolbar

Scheduled Pinned Locked Moved Unsolved Qt for Python
17 Posts 5 Posters 3.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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Hi!
    In qtoolbar, a drop-down menu appears when you right-click. How do I add qaction to this menu?

    1 Reply Last reply
    0
    • RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #2

      @Mikeeeeee

      Did you mean add an QAction to QToolbar?

      toolbar = QToolBar("My main toolbar")
      self.addToolBar(toolbar)
      
      action = QAction("Your button", self)
      toolbar.addAction(action)
      

      --Alles ist gut.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        @Ratzz said in how to add qaction to the menu in qtoolbar:

        toolbar.addAction(action)

        So QAction will be added to the toolBar, but I need to add it to the menu that opens when the right mouse button is clicked

        jsulmJ JonBJ 2 Replies Last reply
        -1
        • M Mikeeeeee

          @Ratzz said in how to add qaction to the menu in qtoolbar:

          toolbar.addAction(action)

          So QAction will be added to the toolBar, but I need to add it to the menu that opens when the right mouse button is clicked

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mikeeeeee There are many addAction(...) methods in QMenu. Also see https://doc.qt.io/qt-5/qwidget.html#customContextMenuRequested

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Mikeeeeee

            @Ratzz said in how to add qaction to the menu in qtoolbar:

            toolbar.addAction(action)

            So QAction will be added to the toolBar, but I need to add it to the menu that opens when the right mouse button is clicked

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

            @Mikeeeeee
            So search the https://doc.qt.io/qt-5/qmenu.html page for all the addAction() methods?

            But I don't think that's what you mean. Can't run Qt right now, but if you say there is a menu when you right-click a QToolbar, does How to add an entry to toolbar context menu in qt? answer what you want to do?

            1 Reply Last reply
            2
            • M Offline
              M Offline
              Mikeeeeee
              wrote on last edited by
              #6

              How can I get this menu from the toolBar and add QAction to it?

              JonBJ 1 Reply Last reply
              -1
              • M Mikeeeeee

                How can I get this menu from the toolBar and add QAction to it?

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

                @Mikeeeeee
                Is that not exactly what the stackoverflow post I pointed you to addresses?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  Mikeeeeee
                  wrote on last edited by
                  #8

                  @JonB said in how to add qaction to the menu in qtoolbar:

                  Is that not exactly what the stackoverflow post I pointed you to addresses?

                  That's not it. I already have a menu in the toolbar. The menu is created automatically. How can I get a pointer to a menu and add qaction to it?

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

                    Hi,

                    What do you have currently in that drop down menu ?
                    How are your initialization that toolbar ?
                    What exactly is your goal with these additional actions ?

                    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
                    • M Offline
                      M Offline
                      Mikeeeeee
                      wrote on last edited by
                      #10

                      Now the menu has change the visibility of the toolbar and dockwidget. I want to add the visibility of other dockwidgets.

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

                        Then add the the other dock widgets toggle actions to it.

                        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
                        • M Offline
                          M Offline
                          Mikeeeeee
                          wrote on last edited by
                          #12

                          How can I do this?

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

                            The same way you did for the other dock widget.

                            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
                            • M Offline
                              M Offline
                              Mikeeeeee
                              wrote on last edited by
                              #14

                              It's impossible. What else can you do??

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

                                Well, something different.

                                Seriously, how do you except to get an answer when you do not show your code, do not explain what you tried, in fact just nothing ?

                                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
                                1
                                • M Offline
                                  M Offline
                                  Mikeeeeee
                                  wrote on last edited by
                                  #16

                                  I don't show my code because my code isn't there. I put widgets in the designer and the menu appeared automatically. Now I need to get a pointer to this menu.

                                  JonBJ 1 Reply Last reply
                                  0
                                  • M Mikeeeeee

                                    I don't show my code because my code isn't there. I put widgets in the designer and the menu appeared automatically. Now I need to get a pointer to this menu.

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

                                    @Mikeeeeee said in how to add qaction to the menu in qtoolbar:

                                    the menu appeared automatically

                                    This is not magic. You can learn an awful lot by looking at the code generated into the ui....h file (in the debug output folder) from uic. Hopefully you will see how this menu is generated, and how you might access it.

                                    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