Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is it possible to outline (stroke) menu text?
Qt 6.11 is out! See what's new in the release blog

Is it possible to outline (stroke) menu text?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sol_aries
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      akonradwesolutions
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sol_aries
        wrote on last edited by
        #3

        Thanks Arnold!

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

        1 Reply Last reply
        0
        • A Offline
          A Offline
          akonradwesolutions
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved