Results 1 to 2 of 2

Thread: QMenuBar and QMenu colors

  1. #1
    Join Date
    Apr 2012
    Posts
    43
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default QMenuBar and QMenu colors

    Hi, I have problem with setting up background colors for my QMenuBar corectly. I have this code:

    Qt Code:
    1. //mainWindow, actions and fileMenu is defined in header file
    2.  
    3. mainWindow.setStyleSheet("background-color: #fcfcfc;");
    4. menuBar()->setStyleSheet("background-color: #4d4d4d; selection-background-color: #fcfcfc;");
    5.  
    6. /*----------MENU----------*/
    7. //menu File
    8.  
    9. changePinAction = new QAction("Change PIN...");
    10. changePukAction = new QAction("Change PUK...");
    11. //and some more actions
    12.  
    13. fileMenu = menuBar()->addMenu(tr("Soubor"));
    14. fileMenu->addAction(changePinAction);
    15. fileMenu->addAction(changePukAction);
    16. //and some more addActoins for other QActions
    To copy to clipboard, switch view to plain text mode 

    This way I created whole menu, but problem is, that StyleSheet is applied inside the menu but not on "Soubor" and other menu headings as shown on attached screenshot and I dont know how to chage it. Any help with that?

    screen.jpg

  2. #2
    Join Date
    Sep 2011
    Location
    Portugal
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMenuBar and QMenu colors

    You don't need to set the stylesheet to each component.
    If you set the stylesheet to the MainWindow, all child widgets will render with that stylesheet.
    If you need to set different styles, just set an object name and filter that in your QSS.
    For styling QMenuBar and QMenu, set the stylesheet on your mainWindow object, according to this:

    http://qt-project.org/doc/qt-4.8/sty...izing-qmenubar
    http://qt-project.org/doc/qt-4.8/sty...tomizing-qmenu

    I hope this helps.

Similar Threads

  1. how to add seperator into QMenuBar?
    By josentop in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2011, 14:11
  2. how to add widget to QMenubar
    By Prashant Moglaikar in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2011, 11:04
  3. QMenuBar and QGraphicsScene
    By Baleg in forum Qt Programming
    Replies: 0
    Last Post: 20th April 2011, 20:39
  4. QMenuBar Updates
    By johnmauer in forum Qt Programming
    Replies: 5
    Last Post: 20th January 2010, 13:35
  5. QMenuBar and QMenu
    By thedoctor in forum Qt Programming
    Replies: 0
    Last Post: 21st December 2009, 21:01

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.