Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Binding list from C++ to QML
Forum Updated to NodeBB v4.3 + New Features

Binding list from C++ to QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qml binding
25 Posts 3 Posters 14.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.
  • P p3c0
    3 Nov 2015, 09:53

    @TonyN

    But then now, I find out that the QAbstractTableModel may not the right choice :~) Despite I implemented columnCount(), it only ask for data in rows of column 0!!

    That's right GridView or ListView only deals with rows. In that case can't you replace it with QAbstractItemModel ? Keep everything other than columns.

    T Offline
    T Offline
    TonyN
    wrote on 3 Nov 2015, 15:49 last edited by
    #21

    @p3c0 Uh but then which view should I use? I read this,
    "QAbstractItemModel presents a hierarchy of tables, but the views currently provided by QML can only display list data."
    Does that mean, at the present time, nothing I can use except maybe create my own view!? If so, what is the best reading can you recommend?

    1 Reply Last reply
    0
    • P p3c0
      3 Nov 2015, 09:53

      @TonyN

      But then now, I find out that the QAbstractTableModel may not the right choice :~) Despite I implemented columnCount(), it only ask for data in rows of column 0!!

      That's right GridView or ListView only deals with rows. In that case can't you replace it with QAbstractItemModel ? Keep everything other than columns.

      T Offline
      T Offline
      TonyN
      wrote on 3 Nov 2015, 23:44 last edited by
      #22

      @p3c0 I solved the problem! Even without doing custom roles. I just simplified it, adding some qRegisterMetaType. The solution is not as I want to be, but it works. For now, I just have to figure out how to hide the dummy items. Thank you for pointing out some direction.

      P 1 Reply Last reply 4 Nov 2015, 05:51
      0
      • T TonyN
        3 Nov 2015, 23:44

        @p3c0 I solved the problem! Even without doing custom roles. I just simplified it, adding some qRegisterMetaType. The solution is not as I want to be, but it works. For now, I just have to figure out how to hide the dummy items. Thank you for pointing out some direction.

        P Offline
        P Offline
        p3c0
        Moderators
        wrote on 4 Nov 2015, 05:51 last edited by p3c0 11 Apr 2015, 05:52
        #23

        @TonyN Congratulations :)
        IMO you can use QAbstractItemModel with GridView(for grid like item positioning) or ListView (for list like item positioning). For hiding dummy items you can maintain a field for items and update it from the model whenever required.

        157

        T 1 Reply Last reply 4 Nov 2015, 14:25
        0
        • P p3c0
          4 Nov 2015, 05:51

          @TonyN Congratulations :)
          IMO you can use QAbstractItemModel with GridView(for grid like item positioning) or ListView (for list like item positioning). For hiding dummy items you can maintain a field for items and update it from the model whenever required.

          T Offline
          T Offline
          TonyN
          wrote on 4 Nov 2015, 14:25 last edited by
          #24

          @p3c0 I certainly want to hear other opinion. I did attempt to use QAbstractItemModel, but then the GridView still treat model as a list!?
          (my current solution is using QAbstractListModel with GridView, and compute item's index from its specified row and column, if there is no item at the requested index, I just return QVariant(). The rowCount() of QAbstractItemModel is the total item the can represent on the grid (row * column) )

          P 1 Reply Last reply 5 Nov 2015, 05:45
          0
          • T TonyN
            4 Nov 2015, 14:25

            @p3c0 I certainly want to hear other opinion. I did attempt to use QAbstractItemModel, but then the GridView still treat model as a list!?
            (my current solution is using QAbstractListModel with GridView, and compute item's index from its specified row and column, if there is no item at the requested index, I just return QVariant(). The rowCount() of QAbstractItemModel is the total item the can represent on the grid (row * column) )

            P Offline
            P Offline
            p3c0
            Moderators
            wrote on 5 Nov 2015, 05:45 last edited by
            #25

            @TonyN GridView doesnot have the facility to get items using columns. AFAIK your current solution is the only way to go. Btw inside GridView you already have the index attached property.

            157

            1 Reply Last reply
            0

            21/25

            3 Nov 2015, 15:49

            • Login

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