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. QToolButton::showMenu() as wrapper of virtual function
QtWS25 Last Chance

QToolButton::showMenu() as wrapper of virtual function

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 634 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.
  • E Offline
    E Offline
    Eugene Zelenko
    wrote on 1 Jun 2021, 23:05 last edited by
    #1

    Hi!

    I need to generate dynamically menu shown by QToolButton. Current implementation doesn't allow this because showMenu() is slot. I'll be great to make it wrapper over virtual function, so old behavior would be preserved and menu could be customized before its appearance.

    J 1 Reply Last reply 2 Jun 2021, 04:24
    0
    • E Eugene Zelenko
      1 Jun 2021, 23:05

      Hi!

      I need to generate dynamically menu shown by QToolButton. Current implementation doesn't allow this because showMenu() is slot. I'll be great to make it wrapper over virtual function, so old behavior would be preserved and menu could be customized before its appearance.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 2 Jun 2021, 04:24 last edited by
      #2

      @Eugene-Zelenko Can you explain your use case?
      You set the menu using https://doc.qt.io/qt-5/qtoolbutton.html#setMenu before calling showMenu().

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      E 1 Reply Last reply 3 Jun 2021, 17:59
      1
      • J jsulm
        2 Jun 2021, 04:24

        @Eugene-Zelenko Can you explain your use case?
        You set the menu using https://doc.qt.io/qt-5/qtoolbutton.html#setMenu before calling showMenu().

        E Offline
        E Offline
        Eugene Zelenko
        wrote on 3 Jun 2021, 17:59 last edited by
        #3

        @jsulm QToolButton is added as cornerWidget to QTabWidget to show list of all tabs (in some cases long and not fitting screen) to switch between them. Currently code keeps track of tab insertions and removals to keep QToolButton menu updated. However, it'll be much easier to generate menu on demand when button clicked. Current implementation of QToolButton doesn't allow it because of limitations described in original post.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 3 Jun 2021, 18:33 last edited by
          #4

          Hi
          And you cant just replace the corner widget using
          https://doc.qt.io/qt-5/qtabwidget.html#setCornerWidget
          and then connect to slot when clicked and there show a menu ?

          E 1 Reply Last reply 3 Jun 2021, 18:52
          0
          • M mrjj
            3 Jun 2021, 18:33

            Hi
            And you cant just replace the corner widget using
            https://doc.qt.io/qt-5/qtabwidget.html#setCornerWidget
            and then connect to slot when clicked and there show a menu ?

            E Offline
            E Offline
            Eugene Zelenko
            wrote on 3 Jun 2021, 18:52 last edited by Eugene Zelenko 6 Mar 2021, 18:53
            #5

            @mrjj showMenu is called in QToolButton::mousePressEvent before call of base QAbstractButton::mousePressEvent with subsequent QAbstractButtonPrivate::emitPressed (in Qt 5.14.2).

            M 1 Reply Last reply 3 Jun 2021, 19:26
            0
            • E Eugene Zelenko
              3 Jun 2021, 18:52

              @mrjj showMenu is called in QToolButton::mousePressEvent before call of base QAbstractButton::mousePressEvent with subsequent QAbstractButtonPrivate::emitPressed (in Qt 5.14.2).

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 3 Jun 2021, 19:26 last edited by
              #6

              @Eugene-Zelenko
              ok. and QToolButton::showMenu() was more code than i expected so
              to fully support orientation etc its a bit of work.

              I was wondering if an event filter could let us handle the menu but i guess not.

              It's very unlikely they would change it to be virtual but feel free to open an enhancement report on
              https://bugreports.qt.io/secure/Dashboard.jspa

              E 1 Reply Last reply 3 Jun 2021, 20:01
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 3 Jun 2021, 19:30 last edited by Christian Ehrlicher 6 Mar 2021, 19:31
                #7

                @mrjj said in QToolButton::showMenu() as wrapper of virtual function:

                It's very unlikely they would change it to be virtual

                At least not before Qt7 :)

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                1
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 3 Jun 2021, 19:35 last edited by
                  #8

                  Maybe override QToolButton::mousePressEvent(), update your menu and call the base class impl then.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  E 1 Reply Last reply 3 Jun 2021, 19:51
                  0
                  • C Christian Ehrlicher
                    3 Jun 2021, 19:35

                    Maybe override QToolButton::mousePressEvent(), update your menu and call the base class impl then.

                    E Offline
                    E Offline
                    Eugene Zelenko
                    wrote on 3 Jun 2021, 19:51 last edited by Eugene Zelenko 6 Mar 2021, 19:52
                    #9

                    @Christian-Ehrlicher Aren't buttons could be pressed with keyboard? I think it's better to have single entry point than re-implement multiple event handlers.

                    1 Reply Last reply
                    0
                    • M mrjj
                      3 Jun 2021, 19:26

                      @Eugene-Zelenko
                      ok. and QToolButton::showMenu() was more code than i expected so
                      to fully support orientation etc its a bit of work.

                      I was wondering if an event filter could let us handle the menu but i guess not.

                      It's very unlikely they would change it to be virtual but feel free to open an enhancement report on
                      https://bugreports.qt.io/secure/Dashboard.jspa

                      E Offline
                      E Offline
                      Eugene Zelenko
                      wrote on 3 Jun 2021, 20:01 last edited by
                      #10

                      @mrjj Enhancement request had been opened.

                      1 Reply Last reply
                      1
                      • C Offline
                        C Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 4 Jun 2021, 04:49 last edited by
                        #11

                        You can also modify the menu when the reason for the menu change changes. Your suggestion will most likly die somewhere in the next few years so you have to find a solution now.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        E 1 Reply Last reply 4 Jun 2021, 04:57
                        0
                        • C Christian Ehrlicher
                          4 Jun 2021, 04:49

                          You can also modify the menu when the reason for the menu change changes. Your suggestion will most likly die somewhere in the next few years so you have to find a solution now.

                          E Offline
                          E Offline
                          Eugene Zelenko
                          wrote on 4 Jun 2021, 04:57 last edited by
                          #12

                          @Christian-Ehrlicher As I wrote, I have working solution, but it's not most elegant one.

                          1 Reply Last reply
                          0

                          5/12

                          3 Jun 2021, 18:52

                          • Login

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