View Full Version : Set text color for menu item
stella1016
16th March 2010, 08:07
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:
QAction *show_XZ_action = new QAction("Show XZ plane", this);
show_XZ_action->setCheckable(true);
....
gl_menu->addAction(show_XZ_action);
aamer4yu
16th March 2010, 08:28
What stylesheet or palette did you try ?
stella1016
16th March 2010, 08:50
I want to do it like:
QColor XZCol(150, 0, 150);
QPalette palette = show_XZ_action->palette();
palette.setBrush(QPalette::WindowText, QBrush(XZCol));
But show_XZ_action is not a widget, not palette() function...
Lykurg
16th March 2010, 09:15
But show_XZ_action is not a widgetBut QMenu is. Try to applay your palette to your menu.
stella1016
16th March 2010, 09:20
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?
aamer4yu
16th March 2010, 10:16
You can get the menu for action by QAction::menu ()
Then I guess you can do it ?
stella1016
16th March 2010, 10:27
You can get the menu for action by QAction::menu ()
Then I guess you can do it ?
You mean like this:
QAction *show_XZ_action = new QAction("Show XZ plane", this);
show_XZ_action->setCheckable(true);
....
gl_menu->addAction(show_XZ_action);
....
QColor XZCol(150, 0, 150);
QPalette palette = show_XZ_action->menu()->palette();
palette.setBrush(QPalette::WindowText, QBrush(XZCol));
....
It has runtime errors in line "QPalette palette = show_XZ_action->menu()->palette();"
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.