PDA

View Full Version : Stylesheet for ActionsContextMenu - how to?



QPlace
21st August 2009, 05:27
I have QTreeView with custom background color. When I add ActionsContextMenu via
ui.view->setContextMenuPolicy(Qt::ActionsContextMenu); the background of the pop-up window is the same as in background color of treeview.

Question: how to set up background color of actioncontextmenu?

yogeshgokul
21st August 2009, 12:12
Question: how to set up background color of actioncontextmenu?
Try this:

QMenu {
background-color: #ABABAB; /* sets background of the menu */
border: 1px solid black;
}

QPlace
21st August 2009, 15:00
I don't see ActionsContextMenu being exposed for editing in Qt Designer. My guess is that your advise is applicable only if I can get ContextMenu from QWidget programmatically

Looking through QWidget docs I can't find a way to retrieve this type of menu. :eek:
Or - may be there is a way to get this menu for editing in Qt Designer?

yogeshgokul
21st August 2009, 15:04
I meant,
Call:

qApp->setStyleSheet();
And pass the string in this, and check the results.

Like this:

QString ss("QMenu{background-color: #ABABAB;border: 1px solid black;}");
qApp->setStyleSheet(ss);

QPlace
21st August 2009, 15:18
Perfect. The only change I made is that I set setStyleSheet against control where I am setting the actionContextMenu. Setting it against application instance changes the main menu but not actionContextMenu in the control that I am interersted in.
I suspect that it does not change in my case because I am setting custom stylesheet for the control _after_ application receives stylesheet change. I'll check it later.

No. Changing stylesheet on QApp level does not change the stylesheet for the control's menu. Has to be done explicitly for the control.
Thanks again!

yogeshgokul
21st August 2009, 15:51
No. Changing stylesheet on QApp level does not change the stylesheet for the control's menu. Has to be done explicitly for the control.

Then do it !;)