Results 1 to 8 of 8

Thread: applying styles to single QAction

  1. #1
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default applying styles to single QAction

    hello, i'm creating an application with QMenu's, and i want to apply a stylesheet to a single QAction item, but QAction has not setStyleSheet method, how can i apply a custom style to a SINGLE QAction?

  2. #2
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: applying styles to single QAction

    does anybody know?

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: applying styles to single QAction

    A QAction has no visible representation, i.e. it is not a QWidget, so applying a style to it directly makes little sense. You would have to address this through a stylesheet on the QToolbar or QMenu

    What effect are you trying to achieve for a particular entry on a menu?

  4. #4
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: applying styles to single QAction

    set a different background for a single QAction, something to "highlight" the QAction, something to emphasize it

  5. #5
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: applying styles to single QAction

    or is it posible to assign an id to QActio as in html? maybe setting the style for QMenu:item#singleitemid works, but i don't how to set the object's id

  6. #6
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: applying styles to single QAction

    You set the QAction's objectName() with setObjectName() (see QObject). I'm not sure the QAction is the object that the :item subcontrol refers to though.

  7. #7
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: applying styles to single QAction

    Quote Originally Posted by htroyo View Post
    or is it posible to assign an id to QActio as in html? maybe setting the style for QMenu:item#singleitemid works, but i don't how to set the object's id
    Yep it is. Try: QAction::data.

  8. #8
    Join Date
    Apr 2011
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: applying styles to single QAction

    unfortunately QAction::setObjectName() didn't work for setting the style for the single QAction, but thanks anyway...
    and why data()? i read documentation but i don't understant the QVariant class and how can i use it, could you explain me please?
    or another alternative?

Similar Threads

  1. Learning more about styles
    By bruccutler in forum Newbie
    Replies: 4
    Last Post: 20th February 2010, 09:09
  2. Different text styles in a single cell of QTableView?
    By xfurrier in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2009, 06:49
  3. GUI Styles
    By dsmcc in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2008, 15:58
  4. PyQt Styles
    By awestman in forum Qt Programming
    Replies: 0
    Last Post: 17th October 2008, 13:59
  5. Styles - building
    By Salazaar in forum Newbie
    Replies: 10
    Last Post: 20th May 2007, 18:19

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.