Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    10
    2637
    Loading More Posts
    • 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
      deleted1 last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • D
          deleted1 last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • D
              deleted1 last edited by

              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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                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 Reply Quote 0
                • D
                  deleted1 last edited by

                  @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 Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    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 Reply Quote 0
                    • D
                      deleted1 last edited by

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

                      Why do you ask?

                      1 Reply Last reply Reply Quote 0
                      • SGaist
                        SGaist Lifetime Qt Champion last edited by

                        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 Reply Quote 0
                        • First post
                          Last post