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. [SOLVED] QListView - make a list of items that are collections of widgets?

[SOLVED] QListView - make a list of items that are collections of widgets?

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.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.
  • D Offline
    D Offline
    deleted1
    wrote on last edited by
    #1

    Hi,

    If someone could just point me in the right direction, that'd be great.

    I want to make a scrollable, drag-and-dropable list of things. Each thing is a collection of widgets (label, check box, some other options.) I've looked at QAbstractListModel, QAbstractItemView, QStyledItemDelegate and other but I'm confused as to the right way to approach this problem.

    Could someone point me to a help page or an example on how to use a QListView as a container for containers of widgets?

    Thank you!

    Edit: I’m writing from scratch so I’m open to any design. I’d suspect that there is a “Qt way” and I want to learn that.

    Here’s a visual example: https://dl.dropboxusercontent.com/u/9258942/mockup.png

    The normal QtListView is the image on the left – Normal ListBox.
    The list I need to create is on the right – Custom ListBox.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      From a design point of view you should create a custom model based on QAbstractListModel that will interact with your list of "thing".

      For more ideas, you should give some information about your container like how are you storing that container ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        I'm writing from scratch so I'm open to any design. I'd suspect that there is a "Qt way" and I want to learn that.

        Here's a visual example: https://dl.dropboxusercontent.com/u/9258942/mockup.png

        The normal QtListView is the image on the left - Normal ListBox.
        The list I need to create is on the right - Custom ListBox.

        thanks

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Should that only be an image of the widget collection of an element or should it also be usable in-place ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

            SOLVED: "setItemWidget":http://doc.qt.io/qt-5/qlistwidget.html#setItemWidget is what I was looking for.

            Here's the code (comments/corrections/improvements welcome!):

            @ lw = QListWidget()

            for var in range( 0, 10 ):
                
                w = QGroupBox()
                vbl = QVBoxLayout( w )
            
                # Row 1 ----------  
                fm = QFrame()
                #fm.setFrameStyle( QFrame.Panel )
                
                hz1 = QHBoxLayout( fm )
                hz1.setSizeConstraint( QLayout.SetFixedSize )
                lbl1 = QLabel( "Item %d" % var )
                spn = QSpinBox()
                spn.setValue( 3 )
                
                hz1.addWidget( lbl1 )
                hz1.addWidget( spn )
                # end Row 1----------  
                
                # Row 2 ----------  
                fm2 = QFrame()
                #fm2.setFrameStyle( QFrame.Panel )
                
                hz2 = QHBoxLayout( fm2 )
                hz2.setSizeConstraint( QLayout.SetFixedSize )
                cb = QCheckBox( "Enabled")
                cmb = QComboBox()
                cmb.addItem( "Choice" )
                
                hz2.addWidget( cb )
                hz2.addWidget( cmb )
                # end Row 2----------  
                
                vbl.addWidget( fm )
                vbl.addWidget( fm2 )
                vbl.setSizeConstraint( QLayout.SetFixedSize )
                
                lwi = QListWidgetItem()
                lwi.setSizeHint( vbl.sizeHint() )
                lw.addItem( lwi )
                lw.setItemWidget( lwi, w )
            
            lw.show()    
            

            @

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Beware, setItemWidget comes with a performance cost especially if you have many widgets in there.

              What is your software purpose ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • D Offline
                D Offline
                deleted1
                wrote on last edited by
                #7

                @SGaist, thanks for the heads up. I'm still pretty green to the Qt ways (but learning quickly.)

                I'm essentially creating a "pipes and filters pattern":http://blog.petersobot.com/pipes-and-filters. Each filter will be represented by the entries in the list box so that each filter can be individually enabled and configured.

                There won't be more than, say, 10 filters which will be used to initialize the list only once at startup. It'll only be running on non-embedded systems (desktop variants) so hopefully performance won't be an issue.

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Will you be adding filters dynamically ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    deleted1
                    wrote on last edited by
                    #9

                    Filters will only be instantiated and then added at startup per the current design.

                    Why do you ask?

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Because you could be writing a drag & drop editor where you could be adding/removing filters dynamically and that could influence the design :)

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      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