I have a two editor classes, say BaseEditor
and AdvancedEditor
. BaseEditor
inherits from QPlaintTextEdit
and its standard context menu follows my style sheet properly.
My AdvancedEditor
now inherits from BaseEditor
and reimplements the method void showContextMenu(const QPoint &point)
to generate a custom context menu. In it I basically do the following:
void AdvancedEditor::showContextMenu(const QPoint &point)
{
QMenu* pStandardMenu = createStandardContextMenu();
QMenu* pMenu = new QMenu();
[add various stuff to pMenu]
connect(pSignalMapper, SIGNAL(mapped(const QString&)), this, SLOT(onContextMenuSelected(const QString&)));
pMenu->addSeparator();
pMenu->addActions(pStandardMenu->actions());
pMenu->exec(mapToGlobal(point));
delete pMenu;
}
This menu however is rendered in the default OS design despite me having the following part in my QSS style sheet (which is properly used for all other menus):
QMenu {
background-color: white;
border: 1px solid #4495D1;
padding: 1px;
}
I tried adding a custom paintEvent()
as described here without any luck: http://qt-project.org/forums/viewthread/25664/#117575. Do I need another PE_* type?
Set pMenu
's parent widget to the one which has your stylesheet.