StyleSheet issues with MainWindow, Menu
-
Hi there,
I'm playing around with stylesheets. Very cool stuff. But I have some issues:
I would expect to set the background to blue to all widgets in the following example. But the button for the menu entry is not styled correctly. It's still shown with the default style.
I'm on a Windows 7 64 bit box using PyQt 4.8.3 for Python 2.7 32 bit.
@import PyQt4.QtGui as QtGui
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) self.menu_bar = self.menuBar() self.session_menu = self.menu_bar.addMenu("&Session") self.setStyleSheet(""" * { background-color: blue; } """)
if name == "main":
import sys
app = QtGui.QApplication(sys.argv)
main_window = MyMainWindow()
main_window.show()
app.exec_() @A bug or do I miss something?
Thanks in advance and cheers,
Jan
-
OK, I've found a solution. You need to select the menu item explicitly. Here's an example that leads to the desired style:
@
import PyQt4.QtGui as QtGuiclass MyMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None): super(MyMainWindow, self).__init__(parent) self.menu_bar = self.menuBar() print self.menu_bar.isNativeMenuBar() self.menu_bar.setNativeMenuBar(False) print self.menu_bar.isNativeMenuBar() self.session_menu = self.menu_bar.addMenu("&Session") button = QtGui.QPushButton("Testomat") self.setCentralWidget(button) self.setStyleSheet(""" * { background-color: blue; } QMenuBar::item { background-color: blue; } """)
if name == "main":
import sys
app = QtGui.QApplication(sys.argv)
main_window = MyMainWindow()
main_window.show()
app.exec_()
@