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();
    }
    @



  • Thanks Arnold!

    I got it to work using your method. It didn't look so good though :/ I decided to do drop shadows instead.



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.