Answer the question
In order to leave comments, you need to log in
PyQt4. How to change the value of a variable when selecting an action from QMenuBar?
Hello. Guys, tell me how to process the choice of the QMenuBar action.
I have a processing function, QMenuBar and action (Action) to it. I need a function to be called when the action is clicked.
Here's an example:
......
def example_func():
print("example!")
example_menubar = QtGui.QMenuBar(self)
example_menu = example_menubar.addMenu('examplemenu')
example_action = example_menu.addAction('ExampleAction1')
example_action2 = example_menu.addAction('ExampleAction2')
Answer the question
In order to leave comments, you need to log in
from PyQt4.QtGui import *
app = QApplication([])
win = QMainWindow()
mainMenu = win.menuBar()
mainMenu.setNativeMenuBar(False)
exampleMenu = mainMenu.addMenu('&Example')
item1 = QAction(QIcon(''), '&Item1', win)
item1.triggered.connect(lambda: print("example!"))
exampleMenu.addAction(item1)
win.show()
app.exec_()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question