Action Button in MenuBar
-
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()
-
@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:- window1() is called, right?
- What happens then? Nothing? Or is wrong page shown?
- What if you use setCurrentIndex instead of setCurrentWidget?
-
@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? -
@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)
-
@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...
-
@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.
-
@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:- window1() is called, right?
- What happens then? Nothing? Or is wrong page shown?
- What if you use setCurrentIndex instead of setCurrentWidget?