Skip to content

Nested QMenu type error #13

Description

@HoseynAAmiri
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions