QMenu stylesheet
-
wrote on 28 Oct 2021, 18:21 last edited by
Hello!
I am creating a QT application and I just created a QMenuBar.
I am trying to style a QMenu but the code does not accept it.NOTE: I am writing the program with VSCode and not with QT Creator.
QT Code: // ========== Menu Item's Configuration ========== this -> start -> setTitle("Start"); this -> help -> setTitle("Help"); // ========== Menu's Configuration ========== this -> menu -> setStyleSheet("QMenuBar { \ background-color: #FFFFFF; \ }"); this -> menu -> addMenu(this -> start); this -> menu -> addMenu(this -> help);
Thanks BTW!
-
Hi and welcome to devnet,
Is
menu
a QMenu ? If so the style sheet won't be applied to the QMenuBar it belongs to as it's a child of the QMenuBar.See the QMenu stylesheet example here.
-
Hello!
I am creating a QT application and I just created a QMenuBar.
I am trying to style a QMenu but the code does not accept it.NOTE: I am writing the program with VSCode and not with QT Creator.
QT Code: // ========== Menu Item's Configuration ========== this -> start -> setTitle("Start"); this -> help -> setTitle("Help"); // ========== Menu's Configuration ========== this -> menu -> setStyleSheet("QMenuBar { \ background-color: #FFFFFF; \ }"); this -> menu -> addMenu(this -> start); this -> menu -> addMenu(this -> help);
Thanks BTW!
wrote on 28 Oct 2021, 18:36 last edited by@SourceCreator said in QMenu stylesheet:
I am trying to style a QMenu but the code does not accept it.
Hello and welcome. Does this mean you get some error when you try to compile it, or something else?
-
wrote on 28 Oct 2021, 18:36 last edited by SourceCreator
@JonB
No. The problem is that the Menu does not take my style. The mingw does not pick up any problems for me. But when executing the program the menu does not show a custom style -
@JonB
No. The problem is that the Menu does not take my style. The mingw does not pick up any problems for me. But when executing the program the menu does not show a custom style@SourceCreator because you wrote a stylesheet for a QMenuBar and not a QMenu.
-
@SourceCreator because you wrote a stylesheet for a QMenuBar and not a QMenu.
wrote on 28 Oct 2021, 18:50 last edited by@SGaist
Okey... I have my styles.qss created and I added this.
My QMenu stills same. -
How are you using now ?
-
wrote on 28 Oct 2021, 19:00 last edited by
@SGaist
I'm using a .qss file
All styles of widgets are working but the one that is not, is the QMenu's one
In this picture, QMenuBar's one is working -
What I meant is how are you loading it ?
-
@SGaist
I'm using a .qss file
All styles of widgets are working but the one that is not, is the QMenu's one
In this picture, QMenuBar's one is workingwrote on 28 Oct 2021, 19:06 last edited by JonB@SourceCreator Which platform are you on? [EDIT: I see you said "VSCode" => Windows]
@SGaist Is menu background color something which requires Fusion style?
[Found reference: [Solved ] Background color of QMenu by StyleSheet doen't work this] -
wrote on 28 Oct 2021, 19:09 last edited by
There's also QMenu::item subcontrols: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenu
-
There's also QMenu::item subcontrols: https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qmenu
wrote on 28 Oct 2021, 19:13 last edited by SourceCreator -
wrote on 28 Oct 2021, 19:16 last edited by JonB
@SourceCreator
TryqApp->setStyle(QStyleFactory::create("fusion")); //or QApplication::setStyle(QStyleFactory::create("Fusion"));
early in your program. Does that change behaviour?
-
wrote on 28 Oct 2021, 19:24 last edited by
@SourceCreator
I don't know what it looks like for you. From the docs example put in theQMenu::item { /* sets background of menu item. set this to something non-transparent if you want menu color and menu item color to be different */ background-color: transparent; }
Does that make it look like it's supposed to?
7/14