QPalette set QMenubar background is not working
Solved
General and Desktop
-
wrote on 6 Apr 2022, 10:03 last edited by
see:
app = QApplication(sys.argv) window = QWidget() menubar = QMenuBar(window) menubar.setAutoFillBackground(True) palette = menubar.palette() palette.setColor(palette.ColorRole.Button, Qt.GlobalColor.blue) # this line palette.setColor(palette.ColorRole.Window, Qt.GlobalColor.red) # this line palette.setColor(palette.ColorRole.ButtonText, Qt.GlobalColor.green) menubar.setPalette(palette) menu = QMenu('File') menubar.addMenu(menu) window.show() if __name__ == '__main__': sys.exit(app.exec())
result:
this result background is no change
i'm beginner,
this why is this result, can't use qpalette on the menubar, use it on the qwidget is good, on the qtoolbar is good, why.
i don't want use to stylesheet.
help me please, thanks! -
Hi and welcome to devnet,
The style used to draw your application may ignore the palette changes you did. See here.
-
wrote on 7 Apr 2022, 02:18 last edited byThis post is deleted!
-
Hi and welcome to devnet,
The style used to draw your application may ignore the palette changes you did. See here.
2/4