1

I Need to create a menubar with multicolour text. For example, In My menubar, My first item name is "File", The first letter of the Item name is in red colour and the remaining letters are in some other different colours. For a More Clear cut Idea, I Enclose a ScheernShot.

enter image description here

import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtCore import QSize


class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setMinimumSize(QSize(300, 100))
        self.setWindowTitle("PyQt menu example ")
        self.aa = 0
        self.intialGui()

    def intialGui(self):
        menu = self.menuBar()
        menu_file = menu.addMenu("&File")
        menu_accounts = menu.addMenu("&Accounts")

        menu_inventory = menu.addMenu('<font color="red"><u>I</u></font><font color="black">nventroy</font>')


if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    mainWin = MainWindow()
    mainWin.show()
    sys.exit( app.exec_() )
tckraomuqnt
  • 470
  • 4
  • 17
  • 1
    Menu titles only use plain text, they don't support rich text. You may try with QProxyStyle, but there's no guarantee that it would work on any OS (and it will *not* work on macOS with the native menubar). – musicamante Jan 18 '22 at 01:59

0 Answers0