Open
Description
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QMenu
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Nested QMenu Example")
self.resize(400, 300)
self.menu_bar = self.menuBar()
self.parent_menu = self.menu_bar.addMenu("Parent Menu")
self.child_menu = QMenu("Child Menu", self)
self.child_menu.addAction("Child Action 1")
self.child_menu.addAction("Child Action 2")
self.parent_menu.addMenu(self.child_menu)
self.parent_menu.addAction("Parent Action")
self.grandchild_menu = QMenu("Grandchild Menu", self)
self.grandchild_menu.addAction("Grandchild Action 1")
self.grandchild_menu.addAction("Grandchild Action 2")
self.child_menu.addMenu(self.grandchild_menu)
self.grandchild_menu.addAction("Another Grandchild Action")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
print(window.menu_bar.actions())
window.show()
sys.exit(app.exec())
the output is [<PyQt6.QtGui.QAction object at 0x000001B599588910>] that is the result of addMenu with text = Parent Menu. However, it is not a QAction, it is a QMenu. This will result in incorrect pylance readout. It's like you cannot see the menus inside the menu.
Metadata
Metadata
Assignees
Labels
No labels