Results 1 to 7 of 7

Thread: Set text color for menu item

  1. #1
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Set text color for menu item

    Hello,

    I want to set different color for the menu item. I know there is stylesheet and palette which can be used. But I failed to find the solution. Anyone knows?

    My code is like below:
    Qt Code:
    1. QAction *show_XZ_action = new QAction("Show XZ plane", this);
    2. show_XZ_action->setCheckable(true);
    3. ....
    4.  
    5. gl_menu->addAction(show_XZ_action);
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set text color for menu item

    What stylesheet or palette did you try ?

  3. #3
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set text color for menu item

    I want to do it like:

    Qt Code:
    1. QColor XZCol(150, 0, 150);
    2. QPalette palette = show_XZ_action->palette();
    3. palette.setBrush(QPalette::WindowText, QBrush(XZCol));
    To copy to clipboard, switch view to plain text mode 

    But show_XZ_action is not a widget, not palette() function...

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Set text color for menu item

    Quote Originally Posted by stella1016 View Post
    But show_XZ_action is not a widget
    But QMenu is. Try to applay your palette to your menu.

  5. #5
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set text color for menu item

    Quote Originally Posted by Lykurg View Post
    But QMenu is. Try to applay your palette to your menu.
    The problem is, I don't want to set color for all items in the menu, but only one item with color. How can I do this?

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Set text color for menu item

    You can get the menu for action by QAction::menu()
    Then I guess you can do it ?

  7. #7
    Join Date
    Jul 2008
    Location
    Munich
    Posts
    73
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Set text color for menu item

    Quote Originally Posted by aamer4yu View Post
    You can get the menu for action by QAction::menu()
    Then I guess you can do it ?
    You mean like this:
    Qt Code:
    1. QAction *show_XZ_action = new QAction("Show XZ plane", this);
    2. show_XZ_action->setCheckable(true);
    3. ....
    4. gl_menu->addAction(show_XZ_action);
    5. ....
    6. QColor XZCol(150, 0, 150);
    7. QPalette palette = show_XZ_action->menu()->palette();
    8. palette.setBrush(QPalette::WindowText, QBrush(XZCol));
    9. ....
    To copy to clipboard, switch view to plain text mode 

    It has runtime errors in line "QPalette palette = show_XZ_action->menu()->palette();"
    Last edited by stella1016; 16th March 2010 at 11:46.

Similar Threads

  1. Replies: 3
    Last Post: 22nd January 2010, 17:46
  2. Menu Item has no highlight
    By blackfox in forum Qt Programming
    Replies: 6
    Last Post: 24th September 2008, 13:17
  3. background color of menu bar
    By sabeesh in forum Qt Programming
    Replies: 6
    Last Post: 24th July 2007, 13:48
  4. Menu bar background color focus
    By user_mail07 in forum Qt Tools
    Replies: 0
    Last Post: 18th May 2007, 02:25
  5. Replies: 1
    Last Post: 17th March 2006, 09: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.