Skip to content

Nested QMenu type error #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
HoseynAAmiri opened this issue Dec 29, 2024 · 0 comments
Open

Nested QMenu type error #13

HoseynAAmiri opened this issue Dec 29, 2024 · 0 comments

Comments

@HoseynAAmiri
Copy link

HoseynAAmiri commented Dec 29, 2024

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())

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant