Is it possible to outline (stroke) menu text?
-
On items (actions) added to Qmenu. Context menu or otherwise. For instance, if I want the main menu of "File", "Open", "Save" to be black font with a white outline. I've seen solutions involving QPen and QBrush (such as http://qt-project.org/forums/viewthread/24195), but those wouldn't work on Qmenu items.
-
You can override the painting performed in QStyle to achieve what you want. The easiest way is to subclass QProxyStyle:
@
class MyProxyStyle : public QProxyStyle
{
protected:
void drawControl(ControlElement element, const QStyleOption * option,
QPainter * painter, const QWidget * widget = 0) const {
if (element == QStyle::CE_MenuItem) {
// Do custom painting
} else {
baseStyle()->drawControl(element, option, painter, widget);
}
}
};
@You can then set an instance of your proxy stile as application style:
@
int main(int argc, char* argv[])
{
QApplication app(argc, argv);MyProxyStyle *style = new MyProxyStyle();
app.setStyle(style);// ...
return app.exec();
}
@ -
You're welcome, I'm glad I could help. I would ask you to mark this thread as solved by prepending [Solved] to the thread title.