Is it possible to outline (stroke) menu text?
-
wrote on 26 Apr 2013, 19:08 last edited by
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.
-
wrote on 27 Apr 2013, 07:47 last edited by
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();
}
@ -
wrote on 27 Apr 2013, 23:06 last edited by
Thanks Arnold!
I got it to work using your method. It didn't look so good though :/ I decided to do drop shadows instead.
-
wrote on 28 Apr 2013, 12:33 last edited by
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.
2/4