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. QPalette set QMenubar background is not working
Forum Updated to NodeBB v4.3 + New Features

QPalette set QMenubar background is not working

Scheduled Pinned Locked Moved Solved General and Desktop
qpalettemenubarqt6
4 Posts 2 Posters 851 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.
  • J Offline
    J Offline
    jiajintao
    wrote on 6 Apr 2022, 10:03 last edited by
    #1

    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:
    565acd47-3d59-44d1-aae5-42448037fe80-image.png
    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!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 6 Apr 2022, 19:34 last edited by
      #2

      Hi and welcome to devnet,

      The style used to draw your application may ignore the palette changes you did. See here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      J 1 Reply Last reply 7 Apr 2022, 02:44
      0
      • J Offline
        J Offline
        jiajintao
        wrote on 7 Apr 2022, 02:18 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • S SGaist
          6 Apr 2022, 19:34

          Hi and welcome to devnet,

          The style used to draw your application may ignore the palette changes you did. See here.

          J Offline
          J Offline
          jiajintao
          wrote on 7 Apr 2022, 02:44 last edited by
          #4

          @SGaist thank your message, i solved it.

          1 Reply Last reply
          0

          1/4

          6 Apr 2022, 10:03

          • Login

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