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. Completely custom menu in QtWidgets
QtWS25 Last Chance

Completely custom menu in QtWidgets

Scheduled Pinned Locked Moved Unsolved General and Desktop
qmenucontext menumaterial designqtwidgets
10 Posts 4 Posters 7.0k 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.
  • I Offline
    I Offline
    IMAN4K
    wrote on 8 Mar 2017, 16:26 last edited by IMAN4K
    #1

    Hi everyone.
    Take a look at this shot:

    enter image description here

    I want to implement such menu.
    It's a part of open source MaterialWidgets project in case of your interest!
    So what way should i go with ?

    1. Derive from QMenu or QWidget ?
    2. What about the shadow ?
    3. I have already implement shadow for the widgets that have parent but what about this ?

    Note: i've already implement button widgets that should placed as menu Action (derived from QAbstractButton)

    M 1 Reply Last reply 9 Mar 2017, 18:45
    0
    • V Offline
      V Offline
      VRonin
      wrote on 8 Mar 2017, 16:35 last edited by
      #2

      if you use QtQuick for UI it's already implemented: https://doc-snapshots.qt.io/qt5-5.7/qtquickcontrols2-material.html

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      I 1 Reply Last reply 8 Mar 2017, 18:45
      2
      • V VRonin
        8 Mar 2017, 16:35

        if you use QtQuick for UI it's already implemented: https://doc-snapshots.qt.io/qt5-5.7/qtquickcontrols2-material.html

        I Offline
        I Offline
        IMAN4K
        wrote on 8 Mar 2017, 18:45 last edited by
        #3

        @VRonin
        Actually i have nothing to do with QtQuick!
        I have designed some basic materialwidgets in pure c++ (QtWidgets) now i want to bring the custom menu i have mentioned and asking for the best way to do that

        1 Reply Last reply
        0
        • I IMAN4K
          8 Mar 2017, 16:26

          Hi everyone.
          Take a look at this shot:

          enter image description here

          I want to implement such menu.
          It's a part of open source MaterialWidgets project in case of your interest!
          So what way should i go with ?

          1. Derive from QMenu or QWidget ?
          2. What about the shadow ?
          3. I have already implement shadow for the widgets that have parent but what about this ?

          Note: i've already implement button widgets that should placed as menu Action (derived from QAbstractButton)

          M Offline
          M Offline
          mostefa
          wrote on 9 Mar 2017, 18:45 last edited by mostefa 3 Sept 2017, 18:45
          #4

          @IMAN4K

          @IMAN4K said in Completely custom menu in QtWidgets:

          So what way should i go with ?

          1. Derive from QMenu or QWidget ?

          For me ,it is better to inherit from QtWidgets ,i think that this will give you a lot of flexibility if you change your component on the future.

          This is just my opinion i don't know if it is the best approach.

          1 Reply Last reply
          1
          • V Offline
            V Offline
            VRonin
            wrote on 9 Mar 2017, 18:50 last edited by
            #5

            I would implement a whole custom style http://doc.qt.io/qt-5/qtwidgets-widgets-styles-example.html
            If you just want this menu then reimplement paintEvent of QMenu

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 9 Mar 2017, 19:27 last edited by mrjj 3 Sept 2017, 19:30
              #6

              Hi
              I think im not seeing what makes it very special.
              So here is something with stylesheet that for me looks alike. (not the line)
              It was quick and dirty so maybe there is tweak potential.

              alt text

              QMenu {
              background-color: white;
               }
               
              QMenu::item {
              padding: 2px 20px 2px 20px;
              border: 1px solid transparent; /* reserve space for selection border */
              spacing: 20px;
               }
               
               
              QMenu::item:selected {
                   border-color: darkblue;
                   background: rgb(53, 120, 191, 150);
              	 color:white;
               }
               
              QMenu::separator {
                   height: 2px;
                   margin: 2px 5px 2px 4px;
               }
               
              QMenu::indicator {
                   width: 20px;
                   height: 13px;
               }
              
              1 Reply Last reply
              4
              • I Offline
                I Offline
                IMAN4K
                wrote on 10 Mar 2017, 16:57 last edited by
                #7

                If i was just about to change only the appearance of menu i choose the sylesheet or QStyle approach.
                But we're talking about complete look and feel and it means we have material ripple animation for items (or actions) .
                So as i mentioned i already implemented a button (derived from QAbstractButton) that can be placed as items.
                So it seems i have 2 options here:
                1.Subclass QWidget + draw base widget (including shadow effect) + draw items (ripple anim & text and may be icon) + draw separator (a big paint method as we have in original QMenu source code) [very flexible way]
                2.Subclass QWidget + draw base widget (including shadow effect) + using a QLayout + QListWidget container to hold the ready items [easy way]

                So which one do you pick ?

                M 1 Reply Last reply 10 Mar 2017, 17:16
                0
                • I IMAN4K
                  10 Mar 2017, 16:57

                  If i was just about to change only the appearance of menu i choose the sylesheet or QStyle approach.
                  But we're talking about complete look and feel and it means we have material ripple animation for items (or actions) .
                  So as i mentioned i already implemented a button (derived from QAbstractButton) that can be placed as items.
                  So it seems i have 2 options here:
                  1.Subclass QWidget + draw base widget (including shadow effect) + draw items (ripple anim & text and may be icon) + draw separator (a big paint method as we have in original QMenu source code) [very flexible way]
                  2.Subclass QWidget + draw base widget (including shadow effect) + using a QLayout + QListWidget container to hold the ready items [easy way]

                  So which one do you pick ?

                  M Offline
                  M Offline
                  mostefa
                  wrote on 10 Mar 2017, 17:16 last edited by mostefa 3 Oct 2017, 17:20
                  #8

                  @IMAN4K said in Completely custom menu in QtWidgets:

                  1.Subclass QWidget + draw base widget (including shadow effect) + draw items (ripple anim & text and may be icon) + draw separator (a big paint method as we have in original QMenu source code) [very flexible way]

                  Instead of drawing separator

                  Can't you just use Line ? as in qt designer?

                  To create a line you can just create a qframe

                     line = new QFrame();
                     line->setFrameShape(QFrame::HLine);
                  

                  http://doc.qt.io/qt-5/qframe.html#Shape-enum

                  QFrame::HLine	0x0004	QFrame draws a horizontal line that frames nothing (useful as separator)
                  

                  After that you could even customize your line with stylesheet !

                  I 1 Reply Last reply 10 Mar 2017, 17:22
                  1
                  • M mostefa
                    10 Mar 2017, 17:16

                    @IMAN4K said in Completely custom menu in QtWidgets:

                    1.Subclass QWidget + draw base widget (including shadow effect) + draw items (ripple anim & text and may be icon) + draw separator (a big paint method as we have in original QMenu source code) [very flexible way]

                    Instead of drawing separator

                    Can't you just use Line ? as in qt designer?

                    To create a line you can just create a qframe

                       line = new QFrame();
                       line->setFrameShape(QFrame::HLine);
                    

                    http://doc.qt.io/qt-5/qframe.html#Shape-enum

                    QFrame::HLine	0x0004	QFrame draws a horizontal line that frames nothing (useful as separator)
                    

                    After that you could even customize your line with stylesheet !

                    I Offline
                    I Offline
                    IMAN4K
                    wrote on 10 Mar 2017, 17:22 last edited by
                    #9

                    @mostefa
                    It's an option and why not!
                    But currently i'm just looking for the whole design choice the first one or the second one

                    M 1 Reply Last reply 10 Mar 2017, 17:44
                    1
                    • I IMAN4K
                      10 Mar 2017, 17:22

                      @mostefa
                      It's an option and why not!
                      But currently i'm just looking for the whole design choice the first one or the second one

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 10 Mar 2017, 17:44 last edited by mrjj 3 Oct 2017, 17:44
                      #10

                      @IMAN4K
                      Hi
                      Im not sure what "material ripple animation" really is so its hard to say which design i would prefer.
                      Copying Paint of QMenu would be last choice as there might be bugs and its involving to keep in sync.

                      If the items can do all the drawing them self i would go for that. (2 i think :)

                      1 Reply Last reply
                      0

                      6/10

                      9 Mar 2017, 19:27

                      • Login

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