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. Accessing item delegate by model index or why Quick sucks when working with models?

Accessing item delegate by model index or why Quick sucks when working with models?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
mvcquickmodeltreev
11 Posts 2 Posters 6.7k 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.
  • K Offline
    K Offline
    Kofr
    wrote on 1 Jun 2016, 21:19 last edited by
    #1

    If I work with Itemdelgate I have proprty model. but how to access property model from a component in model with different index?
    Do I have to write a function which returns model data on C++ side?

    P 1 Reply Last reply 2 Jun 2016, 05:19
    0
    • K Kofr
      1 Jun 2016, 21:19

      If I work with Itemdelgate I have proprty model. but how to access property model from a component in model with different index?
      Do I have to write a function which returns model data on C++ side?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 2 Jun 2016, 05:19 last edited by
      #2

      @Kofr model properties are accessible throughout the delegates.
      Your question is quite confusing. Can you post an example of what you are trying to do ?

      157

      K 1 Reply Last reply 2 Jun 2016, 05:34
      0
      • P p3c0
        2 Jun 2016, 05:19

        @Kofr model properties are accessible throughout the delegates.
        Your question is quite confusing. Can you post an example of what you are trying to do ?

        K Offline
        K Offline
        Kofr
        wrote on 2 Jun 2016, 05:34 last edited by
        #3

        @p3c0 I do not have a si,ple one example.
        I have item delegate 1 item delegate 2.
        I want to get data of item delegate 2 from inside item delegate 1. So I have to use QVariant QAbstractItemModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const manualy from qml.
        And I get problem with updating data as rightCellInput: taskEditLayout.fullMdl.data(taskEditLayout.indx, DataModel.TaskNameRole) does not update binding when data is changed.

        P 1 Reply Last reply 2 Jun 2016, 06:00
        0
        • K Kofr
          2 Jun 2016, 05:34

          @p3c0 I do not have a si,ple one example.
          I have item delegate 1 item delegate 2.
          I want to get data of item delegate 2 from inside item delegate 1. So I have to use QVariant QAbstractItemModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const manualy from qml.
          And I get problem with updating data as rightCellInput: taskEditLayout.fullMdl.data(taskEditLayout.indx, DataModel.TaskNameRole) does not update binding when data is changed.

          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 2 Jun 2016, 06:00 last edited by
          #4

          @Kofr And what are item delegates ?

          157

          K 1 Reply Last reply 2 Jun 2016, 06:24
          0
          • P p3c0
            2 Jun 2016, 06:00

            @Kofr And what are item delegates ?

            K Offline
            K Offline
            Kofr
            wrote on 2 Jun 2016, 06:24 last edited by
            #5

            @p3c0 I have StackView with InitialItem with TreeView which consist of delegates. On Click on delegate in TreeView it pushes to StackView Just another Component "edit window". In this "edit window" there is button to add child to current delegate item (we have tree model). Once I add a child I want the "edit window" of new child to be pushed to stack. But here as I do push from delegate 1 I am not able to pass model property of new delegate. (stack.push(editWndw, {"mdl": taskEditLayout.mdl, "fullMdl": taskEditLayout.fullMdl, "indx": indx}) - here mdl is supposed to be model property of new delegate 2, but Iam not able to get this from delgate 1.

            P 1 Reply Last reply 2 Jun 2016, 07:08
            0
            • K Kofr
              2 Jun 2016, 06:24

              @p3c0 I have StackView with InitialItem with TreeView which consist of delegates. On Click on delegate in TreeView it pushes to StackView Just another Component "edit window". In this "edit window" there is button to add child to current delegate item (we have tree model). Once I add a child I want the "edit window" of new child to be pushed to stack. But here as I do push from delegate 1 I am not able to pass model property of new delegate. (stack.push(editWndw, {"mdl": taskEditLayout.mdl, "fullMdl": taskEditLayout.fullMdl, "indx": indx}) - here mdl is supposed to be model property of new delegate 2, but Iam not able to get this from delgate 1.

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 2 Jun 2016, 07:08 last edited by
              #6

              @Kofr Well in that case instead of passing model object to different components, how about making it global property accessible from everywhere?
              For eg.:
              property QtObject myModel: treeview.model

              157

              K 1 Reply Last reply 2 Jun 2016, 15:36
              0
              • P p3c0
                2 Jun 2016, 07:08

                @Kofr Well in that case instead of passing model object to different components, how about making it global property accessible from everywhere?
                For eg.:
                property QtObject myModel: treeview.model

                K Offline
                K Offline
                Kofr
                wrote on 2 Jun 2016, 15:36 last edited by Kofr 6 Feb 2016, 15:37
                #7

                @p3c0 said:

                treeview.model

                You talk of full model when I need a property attached to delegates.
                may be it is possible to change current delegate somehow.

                P 1 Reply Last reply 3 Jun 2016, 05:17
                0
                • K Kofr
                  2 Jun 2016, 15:36

                  @p3c0 said:

                  treeview.model

                  You talk of full model when I need a property attached to delegates.
                  may be it is possible to change current delegate somehow.

                  P Offline
                  P Offline
                  p3c0
                  Moderators
                  wrote on 3 Jun 2016, 05:17 last edited by
                  #8

                  @Kofr Sorry but I'm unable to undertand the scenario. Is model your own custom property inside delegate ?

                  157

                  K 1 Reply Last reply 3 Jun 2016, 07:02
                  0
                  • P p3c0
                    3 Jun 2016, 05:17

                    @Kofr Sorry but I'm unable to undertand the scenario. Is model your own custom property inside delegate ?

                    K Offline
                    K Offline
                    Kofr
                    wrote on 3 Jun 2016, 07:02 last edited by
                    #9

                    @p3c0 I am talking about this

                    ListView {
                        id: view
                        anchors.fill: parent
                        model: RoleEntryModel {}
                        focus: true
                        delegate: ListDelegate {
                            text: 'hsv(' +
                                  Number(model.hue).toFixed(2) + ',' +
                                  Number(model.saturation).toFixed() + ',' +
                                  Number(model.brightness).toFixed() + ')'
                            color: model.name
                        }
                        highlight: ListHighlight { }
                    }
                    

                    where hue, saturation, brightness are roles of the model.

                    P 1 Reply Last reply 3 Jun 2016, 08:41
                    0
                    • K Kofr
                      3 Jun 2016, 07:02

                      @p3c0 I am talking about this

                      ListView {
                          id: view
                          anchors.fill: parent
                          model: RoleEntryModel {}
                          focus: true
                          delegate: ListDelegate {
                              text: 'hsv(' +
                                    Number(model.hue).toFixed(2) + ',' +
                                    Number(model.saturation).toFixed() + ',' +
                                    Number(model.brightness).toFixed() + ')'
                              color: model.name
                          }
                          highlight: ListHighlight { }
                      }
                      

                      where hue, saturation, brightness are roles of the model.

                      P Offline
                      P Offline
                      p3c0
                      Moderators
                      wrote on 3 Jun 2016, 08:41 last edited by
                      #10

                      @Kofr So is it that you want to access the roles (namely hue, saturation, brightness) values from outside of this ListView delegate ? If so then did you accessing ListVIew model from outside ? Once you get hold of it the data can be accessed too.

                      157

                      K 1 Reply Last reply 3 Jun 2016, 13:21
                      0
                      • P p3c0
                        3 Jun 2016, 08:41

                        @Kofr So is it that you want to access the roles (namely hue, saturation, brightness) values from outside of this ListView delegate ? If so then did you accessing ListVIew model from outside ? Once you get hold of it the data can be accessed too.

                        K Offline
                        K Offline
                        Kofr
                        wrote on 3 Jun 2016, 13:21 last edited by
                        #11

                        @p3c0 said:

                        @Kofr So is it that you want to access the roles (namely hue, saturation, brightness) values from outside of this ListView delegate ? If so then did you accessing ListVIew model from outside ? Once you get hold of it the data can be accessed too.

                        code above is just example, not my case. what I need is to get model.roleName of delegate j when I work in delegate i

                        1 Reply Last reply
                        1

                        5/11

                        2 Jun 2016, 06:24

                        • Login

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