PDA

View Full Version : QMenuBar and QMenu colors



Raadush
29th May 2012, 07:34
Hi, I have problem with setting up background colors for my QMenuBar corectly. I have this code:



//mainWindow, actions and fileMenu is defined in header file

mainWindow.setStyleSheet("background-color: #fcfcfc;");
menuBar()->setStyleSheet("background-color: #4d4d4d; selection-background-color: #fcfcfc;");

/*----------MENU----------*/
//menu File

changePinAction = new QAction("Change PIN...");
changePukAction = new QAction("Change PUK...");
//and some more actions

fileMenu = menuBar()->addMenu(tr("Soubor"));
fileMenu->addAction(changePinAction);
fileMenu->addAction(changePukAction);
//and some more addActoins for other QActions


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?

7761

tferreira
29th May 2012, 11:19
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/stylesheet-examples.html#customizing-qmenubar
http://qt-project.org/doc/qt-4.8/stylesheet-examples.html#customizing-qmenu

I hope this helps.