0

I am trying to add a menu bar at the very top of the application, not "inside" of it where it usually wants to add it.

Quick example:

import sys

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QMenu

class Window(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle("< Menu Go Here")
        self.resize(400, 200)
        self.centralWidget = QLabel("Hello, World")
        self.centralWidget.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.setCentralWidget(self.centralWidget)
        self._createMenuBar()

    def _createMenuBar(self):
        menuBar = self.menuBar()
        menuBar.addMenu(QMenu("&File", self))
        menuBar.addMenu("&Edit")
        menuBar.addMenu("&Help")

if __name__ == "__main__":
    app = QApplication(sys.argv)
    win = Window()
    win.show()
    sys.exit(app.exec_())

Would create something like:

enter image description here

However I want the menu to be part of the grey line above it (same line as the icon and window title).

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
CasualDemon
  • 5,790
  • 2
  • 21
  • 39
  • @musicamante wow, good find. That is not straightforward at all, but does answer the question, thank you! – CasualDemon Sep 30 '21 at 17:46
  • It's not straightforward because Qt doesn't provide a direct implementation of that feature, which is only available for Windows and through its [Window Presentation Foundation](https://en.wikipedia.org/wiki/Windows_Presentation_Foundation). Since Qt is intended to be a cross-platform toolkit, it's not possible to use it, and a custom, complete implementation must be provided. – musicamante Oct 01 '21 at 11:21

0 Answers0