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. Action Button in MenuBar
QtWS25 Last Chance

Action Button in MenuBar

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 2 Posters 1.1k 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.
  • L LT-K101

    Hi,
    I have created a QMenuBar with QMenu object "File" with a sub Qaction button "Add New".
    I want the Qaction button to open a new window. Below is my code, please can anyone confirm if I'm doing the right thing? Thanks.

    self.ui.actionAdd_New.triggered.connect(self.window1)
    
    
     def window1(self):
         self.ui.w = Window1()
         self.ui.w.show()
           
    
    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @LT-K101 said in Action Button in MenuBar:

    please can anyone confirm if I'm doing the right thing?

    Does it work?
    I'm just not sure why you store Window1 instance inside self.ui?

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

    L 1 Reply Last reply
    0
    • jsulmJ jsulm

      @LT-K101 said in Action Button in MenuBar:

      please can anyone confirm if I'm doing the right thing?

      Does it work?
      I'm just not sure why you store Window1 instance inside self.ui?

      L Offline
      L Offline
      LT-K101
      wrote on last edited by
      #3

      @jsulm It does not work though, I was trying my hands on it but I'm stacked. All what I see online is below which works fine.

      self.ui.actionClose.triggered.connect(qApp.exit)
      
      jsulmJ 1 Reply Last reply
      0
      • L LT-K101

        @jsulm It does not work though, I was trying my hands on it but I'm stacked. All what I see online is below which works fine.

        self.ui.actionClose.triggered.connect(qApp.exit)
        
        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @LT-K101 Is window1 called?

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

        L 1 Reply Last reply
        0
        • jsulmJ jsulm

          @LT-K101 Is window1 called?

          L Offline
          L Offline
          LT-K101
          wrote on last edited by
          #5

          @jsulm You mean calling the window1 function when the Qaction Button is clicked?

          jsulmJ 1 Reply Last reply
          0
          • L LT-K101

            @jsulm You mean calling the window1 function when the Qaction Button is clicked?

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

            @LT-K101 Yes, is actionAdd_New triggered, so it calls window1?
            You can simply print something inside window1 to see whether it is called...

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

            L 1 Reply Last reply
            0
            • jsulmJ jsulm

              @LT-K101 Yes, is actionAdd_New triggered, so it calls window1?
              You can simply print something inside window1 to see whether it is called...

              L Offline
              L Offline
              LT-K101
              wrote on last edited by
              #7

              @jsulm When I try to print it works. Displaying a new window is the problem now.

              jsulmJ 1 Reply Last reply
              0
              • L LT-K101

                @jsulm When I try to print it works. Displaying a new window is the problem now.

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

                @LT-K101 How is Window1 implemented? Can you show its code?

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

                L 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @LT-K101 How is Window1 implemented? Can you show its code?

                  L Offline
                  L Offline
                  LT-K101
                  wrote on last edited by LT-K101
                  #9

                  @jsulm It is a QMainWindow with QStackedWidget pages in it. All what I want to do is show the first QStackedWidget page when i trigger the Qmenu action Button.

                  from PyQt5 import QtCore, QtGui, QtWidgets
                  from PyQt5.QtWidgets import QMainWindow, QAction,qApp,QApplication
                  
                  class AdminForm(QtWidgets.QMainWindow):
                  
                      def __init__(self, mainMenu):
                          super(AdminForm, self).__init__()
                          self.mainMenu = mainMenu
                  
                          self.ui = Ui_MainWindow()
                          self.ui.setupUi(self)
                  
                          self.ui.actionClose.triggered.connect(qApp.exit)
                  
                          self.ui.actionAdd_New_Employee.triggered.connect(self.window1)
                  
                  
                      def window1(self):
                          self.ui.stackedWidget.setCurrentWidget(self.ui.First_page)
                  
                  jsulmJ 1 Reply Last reply
                  0
                  • L LT-K101

                    @jsulm It is a QMainWindow with QStackedWidget pages in it. All what I want to do is show the first QStackedWidget page when i trigger the Qmenu action Button.

                    from PyQt5 import QtCore, QtGui, QtWidgets
                    from PyQt5.QtWidgets import QMainWindow, QAction,qApp,QApplication
                    
                    class AdminForm(QtWidgets.QMainWindow):
                    
                        def __init__(self, mainMenu):
                            super(AdminForm, self).__init__()
                            self.mainMenu = mainMenu
                    
                            self.ui = Ui_MainWindow()
                            self.ui.setupUi(self)
                    
                            self.ui.actionClose.triggered.connect(qApp.exit)
                    
                            self.ui.actionAdd_New_Employee.triggered.connect(self.window1)
                    
                    
                        def window1(self):
                            self.ui.stackedWidget.setCurrentWidget(self.ui.First_page)
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @LT-K101 said in Action Button in MenuBar:

                    AdminForm

                    I asked about Window1 which you're trying to show in your window1! Why do you show AdminForm? And why do you have a completely different implementation of window1 in AdminForm than the one you posted before? This is really confusing...

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

                    L 2 Replies Last reply
                    1
                    • jsulmJ jsulm

                      @LT-K101 said in Action Button in MenuBar:

                      AdminForm

                      I asked about Window1 which you're trying to show in your window1! Why do you show AdminForm? And why do you have a completely different implementation of window1 in AdminForm than the one you posted before? This is really confusing...

                      L Offline
                      L Offline
                      LT-K101
                      wrote on last edited by
                      #11

                      @jsulm what I'm showing is the class that controls the button actions with their define functions that can show the QStackedWidget pages .Initially I showed .hide() and .show() which I think is for showing QMainWindows, I stand to be corrected though.

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @LT-K101 said in Action Button in MenuBar:

                        AdminForm

                        I asked about Window1 which you're trying to show in your window1! Why do you show AdminForm? And why do you have a completely different implementation of window1 in AdminForm than the one you posted before? This is really confusing...

                        L Offline
                        L Offline
                        LT-K101
                        wrote on last edited by
                        #12

                        @jsulm This is the GUI of my program, when I click on Add New Staff a pages should open. I'm really confused about how to implement this.

                        Screenshot.png

                        jsulmJ 1 Reply Last reply
                        0
                        • L LT-K101

                          @jsulm This is the GUI of my program, when I click on Add New Staff a pages should open. I'm really confused about how to implement this.

                          Screenshot.png

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

                          @LT-K101 So, unlike you wrote at the beginning you want to show another page when clicking one of the menus (not another window).
                          So, then let go step by step:

                          1. window1() is called, right?
                          2. What happens then? Nothing? Or is wrong page shown?
                          3. What if you use setCurrentIndex instead of setCurrentWidget?

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

                          L 1 Reply Last reply
                          3
                          • jsulmJ jsulm

                            @LT-K101 So, unlike you wrote at the beginning you want to show another page when clicking one of the menus (not another window).
                            So, then let go step by step:

                            1. window1() is called, right?
                            2. What happens then? Nothing? Or is wrong page shown?
                            3. What if you use setCurrentIndex instead of setCurrentWidget?
                            L Offline
                            L Offline
                            LT-K101
                            wrote on last edited by
                            #14

                            @jsulm said in Action Button in MenuBar:

                            setCurrentIndex

                            Thanks a lot I tried the setCurrentIndex method and it worked! like magic.

                            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