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. QAbstractTableModel + QML TableView: How to call setData?
Forum Updated to NodeBB v4.3 + New Features

QAbstractTableModel + QML TableView: How to call setData?

Scheduled Pinned Locked Moved Unsolved General and Desktop
40 Posts 3 Posters 10.5k Views 2 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.
  • B Bremenpl

    @raven-worx thanks for answer. The thing is that at this point I am not certain anymore which version TableView I should opt for. On one hand I dont want to use the obsolete component which has columns and roles functionality mixed, and on the other this.new one doesnt seem to be ready for usage.

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by raven-worx
    #31

    @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

    and on the other this.new one doesnt seem to be ready for usage.

    Based on the example from the docs (untested though):

    TableView {
        id: tableView
    
        columnWidthProvider: function (column) { 
                var colWidth = ...;
                var headerItem = headerRepeater.itemAt(column)
                if( headerItem )
                    headerItem.width = colWidth;
                return colWidth; 
          }
    
        topMargin: header.height
    
        Row {
            id: header
            height: 40
            width: implicitWidth
            padding: 0
            spacing: 0
    
            Repeater {
                id: headerRepeater
                model: tableView.columns 
                Item {
                       height: parent.height
                      // your column delegate
                }
            }
        }
    }
    

    Could be easier/built-in indeed, but i think this should work (with minor adaptions probably).

    QAbstractItemModel::headerData() is directly invokable from within QML

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    B 1 Reply Last reply
    1
    • B Bremenpl

      @raven-worx thanks for answer. The thing is that at this point I am not certain anymore which version TableView I should opt for. On one hand I dont want to use the obsolete component which has columns and roles functionality mixed, and on the other this.new one doesnt seem to be ready for usage.

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #32

      @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

      On one hand I dont want to use the obsolete component which has columns and roles functionality mixed, and on the other this.new one doesnt seem to be ready for usage.

      I'm not aware of a possibility to use headers directly even in the old tebleview

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      B 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

        and on the other this.new one doesnt seem to be ready for usage.

        Based on the example from the docs (untested though):

        TableView {
            id: tableView
        
            columnWidthProvider: function (column) { 
                    var colWidth = ...;
                    var headerItem = headerRepeater.itemAt(column)
                    if( headerItem )
                        headerItem.width = colWidth;
                    return colWidth; 
              }
        
            topMargin: header.height
        
            Row {
                id: header
                height: 40
                width: implicitWidth
                padding: 0
                spacing: 0
        
                Repeater {
                    id: headerRepeater
                    model: tableView.columns 
                    Item {
                           height: parent.height
                          // your column delegate
                    }
                }
            }
        }
        

        Could be easier/built-in indeed, but i think this should work (with minor adaptions probably).

        QAbstractItemModel::headerData() is directly invokable from within QML

        B Offline
        B Offline
        Bremenpl
        wrote on last edited by
        #33

        @raven-worx Thanks for answer, but I am really lost at this one. What is supposed to be my column delegate?

        I am playing with this new TableView for over an hour now and I am not even able to set variable columns width (when the container width change). I wonder either this is a bug or a feature.

        lprzenioslo.zut.edu.pl

        raven-worxR 1 Reply Last reply
        0
        • VRoninV VRonin

          @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

          On one hand I dont want to use the obsolete component which has columns and roles functionality mixed, and on the other this.new one doesnt seem to be ready for usage.

          I'm not aware of a possibility to use headers directly even in the old tebleview

          B Offline
          B Offline
          Bremenpl
          wrote on last edited by
          #34

          @VRonin But would you say the new one or old one is more fit to use...?

          lprzenioslo.zut.edu.pl

          1 Reply Last reply
          0
          • B Bremenpl

            @raven-worx Thanks for answer, but I am really lost at this one. What is supposed to be my column delegate?

            I am playing with this new TableView for over an hour now and I am not even able to set variable columns width (when the container width change). I wonder either this is a bug or a feature.

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #35

            @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

            What is supposed to be my column delegate?

            what every you want it to look like. A Rectangle with a Text inside maybe?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            B 1 Reply Last reply
            1
            • raven-worxR raven-worx

              @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

              What is supposed to be my column delegate?

              what every you want it to look like. A Rectangle with a Text inside maybe?

              B Offline
              B Offline
              Bremenpl
              wrote on last edited by
              #36

              @raven-worx I tried a simple Text component and all that was visible was a single text (not sure either they were stacked one on another).

              Arent you guys aware any single code example showing how to do this all from ground up?

              lprzenioslo.zut.edu.pl

              raven-worxR 1 Reply Last reply
              0
              • B Bremenpl

                @VRonin Yes, I have just checked this. It overlaps my first row... Do you know either rows inserting and removing work? Meaning- If I remove or insert a row at runtime, will it update the view?
                This seems to still be a very beta thing, I wonder either old or new controls should be used.

                VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #37

                I understand and share your frustration on the state of views in QML, development has been focused on components that work well on mobile platforms (as QtWidgets is not really an option there) so views have been neglected.

                @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

                Do you know either rows inserting and removing work?

                It does, the example I linked actually does it

                I have just checked this. It overlaps my first row

                looks like you forgot the topMargin: header.implicitHeight part

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                B 1 Reply Last reply
                0
                • B Bremenpl

                  @raven-worx I tried a simple Text component and all that was visible was a single text (not sure either they were stacked one on another).

                  Arent you guys aware any single code example showing how to do this all from ground up?

                  raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #38

                  @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

                  I tried a simple Text component and all that was visible was a single text (not sure either they were stacked one on another).

                  maybe there is only 1 column?
                  is your model's columnCount() method called?

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  B 1 Reply Last reply
                  0
                  • raven-worxR raven-worx

                    @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

                    I tried a simple Text component and all that was visible was a single text (not sure either they were stacked one on another).

                    maybe there is only 1 column?
                    is your model's columnCount() method called?

                    B Offline
                    B Offline
                    Bremenpl
                    wrote on last edited by
                    #39

                    @raven-worx It is. I will give it another go, thank you.

                    lprzenioslo.zut.edu.pl

                    1 Reply Last reply
                    0
                    • VRoninV VRonin

                      I understand and share your frustration on the state of views in QML, development has been focused on components that work well on mobile platforms (as QtWidgets is not really an option there) so views have been neglected.

                      @Bremenpl said in QAbstractTableModel + QML TableView: How to call setData?:

                      Do you know either rows inserting and removing work?

                      It does, the example I linked actually does it

                      I have just checked this. It overlaps my first row

                      looks like you forgot the topMargin: header.implicitHeight part

                      B Offline
                      B Offline
                      Bremenpl
                      wrote on last edited by
                      #40

                      @VRonin Thanks for answer. I did snap a little bit, sorry for that...
                      I will give the new TableView another go according to yours and @raven-worx hints but as for now I think the Version 1 is more complete. The only lacking thing is to make the TreeView to call setData automatically (I only got this working in the new version). In the 1st version I am still calling a wrapper for it.

                      Thank you for help guys.

                      lprzenioslo.zut.edu.pl

                      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