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. Application wide stylesheet with different styles for menu and context menu?
QtWS25 Last Chance

Application wide stylesheet with different styles for menu and context menu?

Scheduled Pinned Locked Moved Unsolved General and Desktop
cssstylesheetstylesqmenu
6 Posts 3 Posters 6.8k Views
  • 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.
  • D Offline
    D Offline
    dentist
    wrote on last edited by
    #1

    I'm using one stylesheet for my application, actually one for several applications, and naturally when I define styles for QMenu they are used for the menu items of the menubar as well as for the context menues.

    Is there an easy way to define different styles for menu items and context menues?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      Hi @dentist

      Looks like you need to take a look at Qt StyleSheet Doc,

      Customizing QMenu

      Customizing QMenuBar

      Hope this can help !

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dentist
        wrote on last edited by
        #3

        Thanks for the hint, but the issue is not with the entries of the QMenubar (so to say menu headers) but with the QMenu items ( menu entries) . If I design a menubar I get the styling fot the headers with QMenubar but the entries are styled the same as any other QMenu.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mostefa
          wrote on last edited by
          #4

          @dentist

          Can you share a sample code of your stylesheet ?

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dentist
            wrote on last edited by
            #5

            It's just copy paste from the given examples - wanted to check out what I can achieve.

            /* Menubar - does all the styling of the menubar*/
            QMenuBar {
            background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 lightgray, stop:1 darkgray);
            }

            QMenuBar::item {
            spacing: 3px; /* spacing between menu bar items */
            padding: 1px 4px;
            background: transparent;
            border-radius: 4px;
            }

            QMenuBar::item:selected { /* when selected using mouse or keyboard */
            background: #a8a8a8;
            }

            QMenuBar::item:pressed {
            background: #888888;
            }

            /* Menus - context items and menubar items /
            QMenu {
            background-color: rgb(149, 166, 174); /
            grau */
            }

            QMenu::item {
            background-color: transparent;
            }

            QMenu::item:selected {
            background-color: rgb(163, 3, 47); /* rot */
            }

            1 Reply Last reply
            0
            • J.HilkJ Online
              J.HilkJ Online
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              You can define an accessibleName for your objects and distribute different StyleSheets.
              either via the designer or QWidget::setAccessibleName(const QString &name);

              e.g.

              QPushButton{
                 background-color: blue;
              }
              
              QPushButton[accessibleName="SpecialButton1"] {
                 background-color: red;
              }
              

              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              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