Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. StyleSheet issues with MainWindow, Menu
Forum Updated to NodeBB v4.3 + New Features

StyleSheet issues with MainWindow, Menu

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Knacktus
    wrote on 15 Apr 2011, 18:40 last edited by
    #1

    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

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Knacktus
      wrote on 16 Jun 2011, 18:24 last edited by
      #2

      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 QtGui

      class 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_()
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved