0

I'm trying to create a menu but it's not showing though it should, I'm running this in OSX in case it makes any difference.

import sys
from PyQt5.QtWidgets import QApplication, QDesktopWidget, QMainWindow


class WindowTest(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setGeometry(50, 50, 500, 500)
        self.setWindowTitle('Test Window')
        win_rectangle = self.frameGeometry()
        center_point = QDesktopWidget().availableGeometry().center()
        win_rectangle.moveCenter(center_point)
        self.move(win_rectangle.topLeft())
        self.setStyleSheet('QPushButton:!hover {color: red}')
        self.ui()

    def ui(self):
        menu_bar = self.menuBar()
        menu_bar.addMenu('File')
        menu_bar.addMenu('Edit')
        menu_bar.addMenu('Help')
        self.show()


if __name__ == '__main__':
    test = QApplication(sys.argv)
    test_window = WindowTest()
    sys.exit(test.exec_())

The result:

window

  • What do you mean by "It's not showing though it should"? Can you edit your post and embed a screenshot of how it's displayed? – musicamante Feb 21 '20 at 23:33
  • @musicamante here you go, it's an empty window –  Feb 21 '20 at 23:44
  • @sK500 By default, Qt uses the native menubar in MacOS at the top of the screen, and not in the window. Execute `menu_bar.setNativeMenuBar(False)` – eyllanesc Feb 21 '20 at 23:49
  • @eyllanesc Thanks, that fixed the problem. –  Feb 21 '20 at 23:57
  • @sK500 Some menus are not allowed by the native menubar, check the following post: https://stackoverflow.com/questions/60290777 – eyllanesc Feb 21 '20 at 23:57

0 Answers0