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. Can QWidgets be placed into a list view?
Forum Updated to NodeBB v4.3 + New Features

Can QWidgets be placed into a list view?

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 5.6k Views 1 Watching
  • 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
    jesuisbenjamin
    wrote on last edited by
    #1

    Hi,

    I would like to present a scrollable list of widgets (quite large, almost screen-wide in fact). I haven't worked with Qt lists before and I'd like some info before I dig in, so I know what to look for. Here are some questions:

    • can widgets be appended to a list?
    • can list items be indexed and moved remotely to that index (say, by clicking on a button)?
    • can lists scroll horizontally rather than vertically?
    • am I not better of making an elongated widget that moves on mouse wheel event?

    Thanks.
    B.

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Did you try "QAbstractItemView::setIndexWidget() ":http://doc.qt.nokia.com/4.7/qabstractitemview.html#setIndexWidget already?

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jesuisbenjamin
        wrote on last edited by
        #3

        Haa I think that's what I need --- but I am not sure.

        What I want is to make something like a picture-slide, only not with pictures, but widgets functioning as pages. I want them to slide horizontally, per item and not per pixel (so when I scroll an item, it moves to the next and does not stop in the middle of the two).
        Also I want to be able to move from a page to another by index.

        From what I see the QAbstractItemView can do that with "setCurrentIndex()":http://doc.qt.nokia.com/4.7/qabstractitemview.html#setCurrentIndex (?)

        But doesn't abstract mean it is not graphically rendered? I read:
        bq. QAbstractItemView is an abstract class and cannot itself be instantiated.

        Can you explain? Thanks.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jesuisbenjamin
          wrote on last edited by
          #4

          OK i am beginning to make sense of it: QListView inherits the QAbstractItemView and therefore it can use the setCurrentIndex() method.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Abstract in the context of C++ means "not fully implemented". That is: The abstract class defines some methods, but provides no implementation for it. In a header file this is defined by assigning 0 to the method:

            @
            class AbstractBaseClass {
            public
            AbstractBaseClass();
            ~AbstractBaseClass();

            virtual void doSomething();
            virutal void reimplementThis(int a) = 0;
            

            }
            @

            In this example, the AbstractBaseClass provides a (default) implementation of method doSomething, but none for reimplementThis.

            An abstract class cannot be instantiated directly, but only subclasses that implement the missing methods. It can of course be the type of variable to wich an instace of the subclass can be assigned.

            An abstract base class is a good means to define a common interface that all subclasses must implement.

            We mostly refer to the method description of a base class if it is not clear which subclass is in use, or if the subclass does not reimplement that method.

            Regarding your actual problem:
            Qt provides some implementations of the view for different purpoeses: [[Doc:QTableView]] is rendered as a table, [[Doc:QTreeView]] displays a tree like in the different explorers etc., [[Doc:QListView]] provides a list or icon view on the data, [[Doc:QColumnView]] displays hierarchical data on side by side columns. You can choose the on that fits your needs best

            Also, be aware that most of the view have a corresponding xxx widget variant that works without a model.

            For your case, a [[Doc:QListWidget]] seems to be a feasible solution.

            To a achieve the scroll behavior you described call

            @
            viewOrWidget->setVerticalScrollMode( QAbstractItemView:: ScrollPerItem );
            @

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jesuisbenjamin
              wrote on last edited by
              #6

              Thanks for clearing this up. In the meantime, I have discovered the "model-view programming documentation":http://doc.qt.nokia.com/4.6/model-view-programming.html

              QListView indeed seems to be the best, I understand I need to pass a reimplemented QAbstractListModel.

              What I am concerned about however, is how to pass QWidgets into this model. I need to specify the role of the data I pass into the model, but if I look at the "existing roles":http://doc.qt.nokia.com/4.7/qt.html#ItemDataRole-enum, I cannot find any role that allows a QWidget, at best there will be the Qt::DecorationRole, but will that do?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                There is no easy way to put widgets into a model. This is the reason why I would go with a QList widget in this case.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • O Offline
                  O Offline
                  octal
                  wrote on last edited by
                  #8

                  What about creating your own "QStyledItemDelegate":http://doc.qt.nokia.com/latest/qstyleditemdelegate.html

                  To my mind, QListWidget and all other QXXXWidget should be reserved for static content.

                  1 Reply Last reply
                  0
                  • J Offline
                    J Offline
                    jesuisbenjamin
                    wrote on last edited by
                    #9

                    Thanks Octal. That seems OK, but it doesn't tell me whether I can pass in a widget into the model.

                    It seems using a QScrollArea and scroll programmatically using the inherited scrollContentsBy() would do the trick. The viewport then would be an elongated widget, sliding left or right so one section could be seen at a time.

                    What do you think?

                    1 Reply Last reply
                    0
                    • O Offline
                      O Offline
                      octal
                      wrote on last edited by
                      #10

                      Because you don't pass a widget into the model, instead you create your own delegate.

                      Which sort of widget would you want to place into your listview ?

                      1 Reply Last reply
                      0
                      • J Offline
                        J Offline
                        jesuisbenjamin
                        wrote on last edited by
                        #11

                        I want to pass a QFrame holding many children (lists, buttons, labels, icons). What I want is similar to a StackedLayout in function, but with a slide view in appearance, switching from one page to another.

                        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