PDA

View Full Version : QMenu and setStyleSheet



BobTheProg
8th July 2010, 00:15
I have a QMenu (myMenu) and I want to use setStyleSheet to set
-- background to yellow
-- menu item text to red when hovered over.

I have tried zillions of alternatives, including


myMenu.setStyleSheet("* {background-color : yellow } *:hover {color : red }");

I cannot seem to get the right syntax for this. Any help would be gratefully received.
Bob

QbelcorT
8th July 2010, 00:34
hi
Here is my example I used on a QCalendar for the QMenu in it.

QMenu { font-size:18px; width: 150px; color:white; left: 20px; background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);}

BobTheProg
9th July 2010, 01:05
hi
Here is my example I used on a QCalendar for the QMenu in it.

QMenu { font-size:18px; width: 150px; color:white; left: 20px; background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);}

Thanks for the example. But when I use it like this:


myMenu.setStyleSheet("{ font-size:18px; width: 150px; color:white; left: 20px; background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);}");

I get "Could not parse stylesheet of widget" so it looks as if I am missing something fundamental.

suslik
9th July 2010, 01:36
Try:

myMenu.setStyleSheet("QMenu { font-size:18px; width: 150px; color:white; left: 20px; background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 #cccccc, stop: 1 #333333);}");

norobro
9th July 2010, 01:51
From the docs link (http://doc.trolltech.com/4.6/stylesheet-syntax.html)
Style sheets consist of a sequence of style rules. A style rule is made up of a selector and a declaration. You are missing a selector (QMenu or *).

HTH

Drat! Note to self: refresh before posting!

BobTheProg
9th July 2010, 13:28
It works! I knew it would be something obvious, but many many thanks to the members who took the time to point out the obvious.
Bob