Results 1 to 6 of 6

Thread: QMenu and setStyleSheet

  1. #1
    Join Date
    Jan 2010
    Location
    UK
    Posts
    12
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QMenu and setStyleSheet

    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

    Qt Code:
    1. myMenu.setStyleSheet("* {background-color : yellow } *:hover {color : red }");
    To copy to clipboard, switch view to plain text mode 

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

  2. #2
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: QMenu and setStyleSheet

    hi
    Here is my example I used on a QCalendar for the QMenu in it.
    Qt Code:
    1. 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);}
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to QbelcorT for this useful post:

    BobTheProg (9th July 2010)

  4. #3
    Join Date
    Jan 2010
    Location
    UK
    Posts
    12
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu and setStyleSheet

    Quote Originally Posted by QbelcorT View Post
    hi
    Here is my example I used on a QCalendar for the QMenu in it.
    Qt Code:
    1. 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);}
    To copy to clipboard, switch view to plain text mode 
    Thanks for the example. But when I use it like this:

    Qt Code:
    1. 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);}");
    To copy to clipboard, switch view to plain text mode 

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

  5. #4
    Join Date
    Jul 2010
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMenu and setStyleSheet

    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);}");

  6. The following user says thank you to suslik for this useful post:

    BobTheProg (9th July 2010)

  7. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QMenu and setStyleSheet

    From the docs link
    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!

  8. The following user says thank you to norobro for this useful post:

    BobTheProg (9th July 2010)

  9. #6
    Join Date
    Jan 2010
    Location
    UK
    Posts
    12
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMenu and setStyleSheet

    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

Similar Threads

  1. QToolButton & setStyleSheet
    By kavinsiva in forum Newbie
    Replies: 1
    Last Post: 3rd June 2010, 14:52
  2. QTableWidget and setStyleSheet()
    By kazek3018 in forum Newbie
    Replies: 3
    Last Post: 30th December 2008, 08:52
  3. Problem to setstylesheet
    By phillip_Qt in forum Qt Programming
    Replies: 3
    Last Post: 14th April 2008, 06:57
  4. using setStyleSheet
    By Weilor in forum Qt Programming
    Replies: 11
    Last Post: 18th January 2008, 13:41
  5. QApplication::setStyleSheet()
    By Ryhel in forum Qt Programming
    Replies: 1
    Last Post: 15th March 2007, 13:09

Tags for this Thread

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.