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. Add an hamburger icon to a vertical QToolBar
QtWS25 Last Chance

Add an hamburger icon to a vertical QToolBar

Scheduled Pinned Locked Moved General and Desktop
16 Posts 3 Posters 9.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.
  • J Offline
    J Offline
    JulienMaille
    wrote on 15 Sept 2015, 21:36 last edited by JulienMaille
    #5

    https://www.google.fr/search?q=chrome+hamburger+menu&tbm=isch&biw=1920

    To be honest I don't like this kind of implementation: hiding all the mess behind a button. But I would enjoy using simplified toolbars that only show icons but can be extended with text for newbies (exactly like the gif above in the first post)

    M 1 Reply Last reply 15 Sept 2015, 21:46
    0
    • J JulienMaille
      15 Sept 2015, 21:36

      https://www.google.fr/search?q=chrome+hamburger+menu&tbm=isch&biw=1920

      To be honest I don't like this kind of implementation: hiding all the mess behind a button. But I would enjoy using simplified toolbars that only show icons but can be extended with text for newbies (exactly like the gif above in the first post)

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 15 Sept 2015, 21:46 last edited by
      #6

      @JulienMaille
      Ahh I thought that the expanding part was also part of "burger", but now I understand.
      Yes, I agree, its a neat way for compact layout and then can show text when needed.
      Thx for info.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 16 Sept 2015, 00:35 last edited by
        #7

        I thought this could be a nice exercise. This is my stab at it: burger-menu.
        Could use some more customization options but the basic functionality is there.

        M 1 Reply Last reply 16 Sept 2015, 06:29
        0
        • C Chris Kawa
          16 Sept 2015, 00:35

          I thought this could be a nice exercise. This is my stab at it: burger-menu.
          Could use some more customization options but the basic functionality is there.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 16 Sept 2015, 06:29 last edited by
          #8

          @Chris-Kawa
          Very cool !
          And it uses actions so actually pretty complete.
          Even has animation :)

          note:
          to make it compile on Win 7, mingw, I had to add
          QMAKE_CXXFLAGS += -std=c++0x
          to .pro
          and const to
          void setBurgerIcon(QIcon& icon);
          or it did not "see" it.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on 16 Sept 2015, 07:46 last edited by
            #9

            QMAKE_CXXFLAGS += -std=c++0x

            Ah... I wish gcc made this the default already ;) Btw. This option is not recognized by MSVC so it's better to add CONFIG += c++11 instead, to let qmake figure out the right flags for the compiler.

            and const to void setBurgerIcon(QIcon& icon);

            Yup, late night coding ;) Fixed. Thanks!

            M 1 Reply Last reply 16 Sept 2015, 07:52
            0
            • C Chris Kawa
              16 Sept 2015, 07:46

              QMAKE_CXXFLAGS += -std=c++0x

              Ah... I wish gcc made this the default already ;) Btw. This option is not recognized by MSVC so it's better to add CONFIG += c++11 instead, to let qmake figure out the right flags for the compiler.

              and const to void setBurgerIcon(QIcon& icon);

              Yup, late night coding ;) Fixed. Thanks!

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 16 Sept 2015, 07:52 last edited by
              #10

              Yeah, when trying code that use lambdas and its not enabled, it really explodes.

              Oh, so CONFIG += xx is better to use overall ?

              Late night coding is the best :)

              I wonder why is was not named more-menu or something like that as burger-menu is so strange. I mean in general, not your widget.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chris Kawa
                Lifetime Qt Champion
                wrote on 16 Sept 2015, 08:06 last edited by
                #11

                Oh, so CONFIG += xx is better to use overall ?

                Yes, because it will add the flag you mentioned when it's needed (like for gcc) and do nothing when it's not needed (e.g. MSVC doesn't have language version flags, they have the latest they support always enabled).

                I wonder why is was not named more-menu or something like that

                It has many names e.g. side drawer, navigation drawer, side menu... hamburger menu is referring to the three bars icon that sorta looks like hamburger if you put your imagination to it :)
                It's a controversial pattern. Apple discourages it. Windows has adopted it widely in their store apps. Designers all over can't seem to agree on whether it's a good thing or not. It's the same story as with the ribbon some time ago. I guess we are still looking for that holy grail in menu design :)

                M 1 Reply Last reply 16 Sept 2015, 08:19
                0
                • C Chris Kawa
                  16 Sept 2015, 08:06

                  Oh, so CONFIG += xx is better to use overall ?

                  Yes, because it will add the flag you mentioned when it's needed (like for gcc) and do nothing when it's not needed (e.g. MSVC doesn't have language version flags, they have the latest they support always enabled).

                  I wonder why is was not named more-menu or something like that

                  It has many names e.g. side drawer, navigation drawer, side menu... hamburger menu is referring to the three bars icon that sorta looks like hamburger if you put your imagination to it :)
                  It's a controversial pattern. Apple discourages it. Windows has adopted it widely in their store apps. Designers all over can't seem to agree on whether it's a good thing or not. It's the same story as with the ribbon some time ago. I guess we are still looking for that holy grail in menu design :)

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 16 Sept 2015, 08:19 last edited by
                  #12

                  ahh so that is is much smarter. Will use that from now on.

                  Well with all design things, they often disagree, also the users. I hate the new look in windows 8+ as I find it too flat and lifeless but my Colleague loves it and find it nice looking.
                  I think there can only exist a Holy grail for interface design if we remove the users ;)

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    JulienMaille
                    wrote on 16 Sept 2015, 10:12 last edited by
                    #13

                    Good job Chris,
                    Unfortunately I would really like to achieve this by subclassing QToolBar instead of creating a brand new class.
                    Do you see a way to align each item properly within the toolbar?

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Chris Kawa
                      Lifetime Qt Champion
                      wrote on 16 Sept 2015, 10:58 last edited by
                      #14

                      Do you see a way to align each item properly within the toolbar?

                      The alignment of text on QToolButton seems to be style dependent, so the only way I can think of would be to provide a QStyle subclass and draw the QStyle::CE_ToolButtonLabel the way you want. There might be an easier way but I don't know of any.

                      J 1 Reply Last reply 21 Sept 2015, 15:25
                      0
                      • C Chris Kawa
                        16 Sept 2015, 10:58

                        Do you see a way to align each item properly within the toolbar?

                        The alignment of text on QToolButton seems to be style dependent, so the only way I can think of would be to provide a QStyle subclass and draw the QStyle::CE_ToolButtonLabel the way you want. There might be an easier way but I don't know of any.

                        J Offline
                        J Offline
                        JulienMaille
                        wrote on 21 Sept 2015, 15:25 last edited by JulienMaille
                        #15

                        @Chris-Kawa said:

                        The alignment of text on QToolButton seems to be style dependent, so the only way I can think of would be to provide a QStyle subclass and draw the QStyle::CE_ToolButtonLabel the way you want. There might be an easier way but I don't know of any.

                        I had a look at QStyle::CE_ToolButtonLabel and I have the feeling this is not the place to achieve left alignement. The rect of the QToolButton is already centered at this step and all you can do is change the way the text and pixmap are drawn within the rect.
                        I suppose that I should modify the rendering at a higher level (ie. the toolbar and not the toolbaritems) but can't find where.
                        Do you have any experience to share?
                        Thanks a lot

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          Chris Kawa
                          Lifetime Qt Champion
                          wrote on 21 Sept 2015, 16:48 last edited by
                          #16

                          My comment was on a hunch, but I just had a look at QCommonStyle.cpp and it is indeed the place where the text is centered inside a tool button. Take a look at case CE_ToolButtonLabel: in QCommonStyle::drawControl.
                          If you meant aligning of the button itself on the toolbar then yeah, I guess you'd have to take a look at how QToolBar is implemented and does it lay the items itself or delegates that to the style. I never had the need to modify it so I don't know.

                          Btw. Why does it have to be a QToolBar? I think functionality wise it's closer to a QTabBar if anything. Why not a custom class if it does what you need?

                          1 Reply Last reply
                          0

                          14/16

                          16 Sept 2015, 10:58

                          • Login

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