Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my QPushButton overlapping the QMenuBar

I have this QMenuBar and I wanted to put a button on the screen and for some reason it just overlaps the menubar…?

enter image description here

Here is my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class LeagueHelperWindow(QMainWindow):
    def __init__(self) -> None:
        super().__init__()
        self.setWindowTitle('League Helper')
        self.load_saved_settings()
        self.setup_menu_bar()

        self.vbox = QVBoxLayout(self)
        self.setLayout(self.vbox)
        
        self.button = QPushButton('Test', self)
        self.vbox.addWidget(self.button)
        self.vbox.addStretch()

        self.setLayout(self.vbox)
        
    def setup_menu_bar(self):
        menu_bar = QMenuBar(self)

        file_menu = menu_bar.addMenu('File')
        exit_action = file_menu.addAction('Exit')
        exit_action.triggered.connect(self.close)

        view_menu = menu_bar.addMenu('View')
        logs_action = view_menu.addAction('Logs')
        logs_action.setCheckable(True)
        logs_action.triggered.connect(self.display_log_window)

        help_menu = menu_bar.addMenu('Help')
        about_action = help_menu.addAction('About')
        about_action.triggered.connect(about_app)

        self.setMenuBar(menu_bar)

How do I fix this?

>Solution :

Your window has no central Widget

Add this to your constructor.

self.central = QWidget()
self.setCentralWidget(self.central)

and change these lines

self.setLayout(self.vbox)

to


self.central.setLayout(self.vbox)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading