Answer the question
In order to leave comments, you need to log in
PyQt5 Python, open widget when selecting menubar item, how to implement?
Good afternoon, I decided to switch from easygui (I thought I would learn how to work with gui, but this is my own) to pyqt5
I collected 2 layouts in "designer"
1 - Menu bar (glav.ui), and there is a drop-down list of QAction buttons (for example action_1 , action_2)
2 - A window with a widget (widget.ui) there is just text.
How to open widget.ui when clicking on action2
Help(
app = QtWidgets.QApplication([])
app.setStyleSheet(style)
win = uic.loadUi("glav.ui")
win.show()
sys.exit(app.exec())
Answer the question
In order to leave comments, you need to log in
It does not hurt, of course, to bring the code of the forms. You have to give the action a name, and find it through the object received after loading the ui, and connect to the action's signal - the slot:
win = uic.loadUi("main_window.ui")
action = win.findChild(QAction, "your_action_name")
action.triggered.connect(your_object.your_slot)
class MainWindow(QtWidgets.QMainWindow): # ваш базовый класс
def __init__(self):
super(Ui, self).__init__()
uic.loadUi('main_window.ui', self)
action = self.findChild(QAction, "your_action_name")
action.triggered.connect(self.your_slot)
self.show()
def your_slot(self):
pass
widget = uic.loadUi("widget.ui")
widget.show()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question