Search code examples
pythonmacospyqtpyqt5qmenubar

pyqt5 default native menu text on MacOS


Is there a way to change default menu title for native menu on MacOS for a simple pyqt5 app?

enter image description here

I'm trying to change "Python" menu entry on above image. Is there a way to rename it? Can I hide it somehow?

This code prints only "File":

menubar = self.menuBar()
for item in menubar.actions():
    print(item.text())

menubar.setNativeMenuBar(False) doesn't help too (just move "File" into the MainWindow).

Update Sample app code:

from PyQt5 import QtCore, QtWidgets, uic
import sys


class Ui(QtWidgets.QMainWindow):
    def __init__(self):
        super(Ui, self).__init__()
        # QtCore.QCoreApplication.setApplicationName('QtFoo') # doesn't work
        uic.loadUi('App.ui', self)
        self.show()

# app = QtWidgets.QApplication(sys.argv)
app = QtWidgets.QApplication(["MyCoolApp"])
# app.setApplicationName("QtFoo") # doesn't work
# app.setApplicationDisplayName("Display Name")
window = Ui()
app.exec()

Solution

  • If you are not willing to package your app, you could create a temporary symbolic link to python as described here. This link can be used to execute python apps while displaying a custom name in the title bar:

    enter image description here

    1. go to the location of your app (e.g. my_app.py) file in the terminal

    2. create symbolic link (replace location to your python interpreter, replace "BeautifulNaming" with desired name)

      ln -s /Users/Christian/miniconda3/bin/python BeautifulNaming

    3. call link to python with your script

      ./BeautifulNaming my_app.py