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. How to associate QListWidget with QPushButton ?
QtWS25 Last Chance

How to associate QListWidget with QPushButton ?

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 3 Posters 1.6k 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.
  • S Offline
    S Offline
    Sougata1996
    wrote on 12 Jul 2020, 06:49 last edited by
    #4

    @JonB , @mrjj :
    Thanks for the quick response .
    Right , the only reason that i did not use QMenu for this is because i wanted a Vertical Scrollbar with the List . As far as i know Vertical Scrollbar is not supported for QMenu . Or is there a way to have a scrollbar for QMenu Items as well ?

    My requirement is that if there are more than 4 items in the DropDownList a Vertical Scrollbar should appear , which could facilitate the user to scroll down and view the rest of the items .

    Is there a way to do this by QMenu ?

    M 1 Reply Last reply 12 Jul 2020, 06:54
    0
    • S Sougata1996
      12 Jul 2020, 06:49

      @JonB , @mrjj :
      Thanks for the quick response .
      Right , the only reason that i did not use QMenu for this is because i wanted a Vertical Scrollbar with the List . As far as i know Vertical Scrollbar is not supported for QMenu . Or is there a way to have a scrollbar for QMenu Items as well ?

      My requirement is that if there are more than 4 items in the DropDownList a Vertical Scrollbar should appear , which could facilitate the user to scroll down and view the rest of the items .

      Is there a way to do this by QMenu ?

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 Jul 2020, 06:54 last edited by mrjj 7 Dec 2020, 06:57
      #5

      @Sougata1996
      Hi
      As far as i know, QMenu will not show scroll bars.
      Once upon a time you could do
      submenu->setStyleSheet("QMenu { menu-scrollable: 1; }");
      to have sub menus have scrollbars but not sure it still works :)
      update
      It still there but has issues.
      https://bugreports.qt.io/browse/QTBUG-48959
      Also draws funny on Win 10..

      1 Reply Last reply
      2
      • S Offline
        S Offline
        Sougata1996
        wrote on 12 Jul 2020, 07:03 last edited by
        #6

        @mrjj : To display the scrollbar what i am thinking of doing is using QListWidget and customising the QListWidgetItems to be of QMenu type by using the method QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget) . The second parameter that i will pass will be of QMenu type .

        Is there any other solution to this , would like to know your opinion about this solution or any other suggestion that you have to overcome this limitation of QMenu .

        M 1 Reply Last reply 12 Jul 2020, 07:14
        0
        • S Sougata1996
          12 Jul 2020, 07:03

          @mrjj : To display the scrollbar what i am thinking of doing is using QListWidget and customising the QListWidgetItems to be of QMenu type by using the method QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget) . The second parameter that i will pass will be of QMenu type .

          Is there any other solution to this , would like to know your opinion about this solution or any other suggestion that you have to overcome this limitation of QMenu .

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 12 Jul 2020, 07:14 last edited by
          #7

          @Sougata1996
          Hi
          Do you really need QMenu on top of the items in QListWidget?
          The item can already have icon + text and you can get signal when you click it and then close
          the Menu so it acts like normal.

          Other solutions would require much more code. If you look at QCombobox, it displays a scroll area for its
          dropdown viewport so it's possible to hand create but then you must handle cases like click outside should close it and
          such.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sougata1996
            wrote on 12 Jul 2020, 07:20 last edited by
            #8

            @mrjj : Screenshot 2020-07-11 at 11.50.09 AM.png
            I agree the QListWidgetItem will have Icon and text both but to display a flyout as shown in this image i will require submenu right ? Or is there is way to have create a flyout like this even by nesting QListWidgetItems ?

            M 1 Reply Last reply 12 Jul 2020, 07:23
            0
            • S Sougata1996
              12 Jul 2020, 07:20

              @mrjj : Screenshot 2020-07-11 at 11.50.09 AM.png
              I agree the QListWidgetItem will have Icon and text both but to display a flyout as shown in this image i will require submenu right ? Or is there is way to have create a flyout like this even by nesting QListWidgetItems ?

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 12 Jul 2020, 07:23 last edited by
              #9

              @Sougata1996
              Hi
              Ah you want to have sub menus..
              No, QListWidget cannot do that at all.

              I never tried using QMenu as item widget but try and see if it works.
              That would be the easiest since you require sub-menus.

              1 Reply Last reply
              2
              • S Offline
                S Offline
                Sougata1996
                wrote on 17 Jul 2020, 08:33 last edited by
                #10

                Hi @mrjj , @SGaist : I was able to use QMenu as ItemWidget and it worked for me , but i am seeing a strange problem which is bugging me :

                Screenshot 2020-07-17 at 1.56.43 PM.png

                As you can see in the above image there is a gap between the highlight and the left border , that it causing a strange issue .

                On clicking in between the highlight and the border my row suddenly disappears :

                Screenshot 2020-07-17 at 1.56.24 PM.png

                One way i was thinking to overcome this might be if my selection covers the entire width of the ListItem instead of leaving any gap . But was not able to achieve it .

                M 1 Reply Last reply 17 Jul 2020, 13:01
                0
                • S Sougata1996
                  17 Jul 2020, 08:33

                  Hi @mrjj , @SGaist : I was able to use QMenu as ItemWidget and it worked for me , but i am seeing a strange problem which is bugging me :

                  Screenshot 2020-07-17 at 1.56.43 PM.png

                  As you can see in the above image there is a gap between the highlight and the left border , that it causing a strange issue .

                  On clicking in between the highlight and the border my row suddenly disappears :

                  Screenshot 2020-07-17 at 1.56.24 PM.png

                  One way i was thinking to overcome this might be if my selection covers the entire width of the ListItem instead of leaving any gap . But was not able to achieve it .

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 17 Jul 2020, 13:01 last edited by
                  #11

                  @Sougata1996
                  Hi
                  Its hard to guess at.
                  Maybe its the menu you hit.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Sougata1996
                    wrote on 20 Jul 2020, 07:46 last edited by Sougata1996
                    #12

                    @mrjj : On some debugging i understood the reason , what is happening is that on clicking outside the menu the list widget item tries to get focus and hides the static content of the QMenu which is inside list widget item . I have used the function setItemWidget() passing the listwidgetitem as first parameter and menu(with icon and text) as the second parameter . Though i could not find a solution to this .

                    M 1 Reply Last reply 20 Jul 2020, 08:07
                    0
                    • S Sougata1996
                      20 Jul 2020, 07:46

                      @mrjj : On some debugging i understood the reason , what is happening is that on clicking outside the menu the list widget item tries to get focus and hides the static content of the QMenu which is inside list widget item . I have used the function setItemWidget() passing the listwidgetitem as first parameter and menu(with icon and text) as the second parameter . Though i could not find a solution to this .

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 20 Jul 2020, 08:07 last edited by
                      #13

                      @Sougata1996
                      Hi
                      I would guess its the QMenu that hides it self as it normally does when you "click outside"
                      It might be possible to catch that using an event filter
                      https://doc.qt.io/qt-5/eventsandfilters.html
                      but i didnt look into that.

                      1 Reply Last reply
                      1
                      • S Offline
                        S Offline
                        Sougata1996
                        wrote on 14 Aug 2020, 09:50 last edited by
                        #14
                        This post is deleted!
                        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