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. I have created an listview inside another listview how can we bind the modeldata from cpp in this type view?
Forum Updated to NodeBB v4.3 + New Features

I have created an listview inside another listview how can we bind the modeldata from cpp in this type view?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 262 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.
  • N Offline
    N Offline
    Neethu Antony
    wrote on 10 Nov 2020, 15:09 last edited by Neethu Antony 11 Oct 2020, 17:10
    #1

    Hi,
    I have created column model and row model and attached the rowmodel to column model. But when i try to access the same it is not working?
    Column mode is TrendsAreaItemModel
    Row model is added in the TrendsAreaItemModel with the role name : NumericTableItemModelRole
    I have added the rowModel as shown below:

    switch(role)
        {
            case NumericTableItemModelRole:
            {
                data =  QVariant::fromValue(m_pNumericItemModel);
    
                break;
            }
    

    Please find the QML code below:

    ListView {
                    id:listmodel
                    clip: true
                    model:TrendsAreaItemModel
                    anchors.fill: parent
                    width:contentWidth
                    height: contentHeight
                    orientation: ListView.Horizontal
                    layoutDirection :Qt.RightToLeft
    //                layoutDirection :Qt.LeftToRight
                    flickableDirection: Flickable.HorizontalFlick
                    boundsBehavior: Flickable.StopAtBounds
                    interactive: false
    
    
                    delegate:
                        Rectangle{
                            id:innerRect
                            width: isWidthExpanded || isCornerExpanded ? 127.2:126
                            height: rectancle1.height
                            color: "#191919"
    
                            ListView{
                                id:innerlist
                                model: model.NumericTableItemModelRole
                                width: innerRect.width
                                height: innerRect.height - innerRect.height/5
                                orientation: ListView.Vertical
                                interactive: false
                                delegate:
                                    Rectangle{
                                       id:rectangle
                                       border.width: 1.5
                                       border.color: "#082931"
                                       color: {
                                           index % 2 == 0? "black":"#191919"
                                       }
                                       width:isWidthExpanded || isCornerExpanded ? 127.2:126
                                       height: innerlist.height/listmodel.currentItem.NumericRowCountRole
                                       Text {
                                           id:text
                                           text: listmodel.currentItem.NumericRowValue
                                           anchors.horizontalCenter: parent.horizontalCenter
                                           anchors.verticalCenter: parent.verticalCenter
                                           color:"white"
                                           font.family: "Arial"
                                           font.pointSize:18
    //                                       id:text
    //                                       text: model.ParameterValue
    //                                       anchors.horizontalCenter: parent.horizontalCenter
    //                                       anchors.verticalCenter: parent.verticalCenter
    //                                       color:model.ParameterName
    //                                       font.family: "Arial"
    //                                       font.pointSize:18
                                       }
                                }
                            }
    
                        }
    //                    add: Transition {
    //        //                NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 400 }
    //        //                NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 400 }
    //                    }
    
                        displaced: Transition {
                            NumberAnimation { properties: "x,y"; duration: 1100;  easing.type: Easing.Linear }
                        }
    
                    focus: true
                    Component.onCompleted: {
    //                    listmodel.positionViewAtEnd()
                        titleRectanchor = titlexrect.left
                        titleRecttopanchor = titlexrect.top
                        listmodel.positionViewAtIndex(model.count - 1, ListView.Visible)
                    }
                    onCountChanged: {
                        listmodel.positionViewAtIndex(model.count - 1, ListView.Visible)
    
                    }
                    ScrollBar.horizontal: ScrollBar {
                        policy:ScrollBar.AlwaysOn
                        active: true
                    }
                }
    
    G 1 Reply Last reply 10 Nov 2020, 16:51
    0
    • N Neethu Antony
      10 Nov 2020, 15:09

      Hi,
      I have created column model and row model and attached the rowmodel to column model. But when i try to access the same it is not working?
      Column mode is TrendsAreaItemModel
      Row model is added in the TrendsAreaItemModel with the role name : NumericTableItemModelRole
      I have added the rowModel as shown below:

      switch(role)
          {
              case NumericTableItemModelRole:
              {
                  data =  QVariant::fromValue(m_pNumericItemModel);
      
                  break;
              }
      

      Please find the QML code below:

      ListView {
                      id:listmodel
                      clip: true
                      model:TrendsAreaItemModel
                      anchors.fill: parent
                      width:contentWidth
                      height: contentHeight
                      orientation: ListView.Horizontal
                      layoutDirection :Qt.RightToLeft
      //                layoutDirection :Qt.LeftToRight
                      flickableDirection: Flickable.HorizontalFlick
                      boundsBehavior: Flickable.StopAtBounds
                      interactive: false
      
      
                      delegate:
                          Rectangle{
                              id:innerRect
                              width: isWidthExpanded || isCornerExpanded ? 127.2:126
                              height: rectancle1.height
                              color: "#191919"
      
                              ListView{
                                  id:innerlist
                                  model: model.NumericTableItemModelRole
                                  width: innerRect.width
                                  height: innerRect.height - innerRect.height/5
                                  orientation: ListView.Vertical
                                  interactive: false
                                  delegate:
                                      Rectangle{
                                         id:rectangle
                                         border.width: 1.5
                                         border.color: "#082931"
                                         color: {
                                             index % 2 == 0? "black":"#191919"
                                         }
                                         width:isWidthExpanded || isCornerExpanded ? 127.2:126
                                         height: innerlist.height/listmodel.currentItem.NumericRowCountRole
                                         Text {
                                             id:text
                                             text: listmodel.currentItem.NumericRowValue
                                             anchors.horizontalCenter: parent.horizontalCenter
                                             anchors.verticalCenter: parent.verticalCenter
                                             color:"white"
                                             font.family: "Arial"
                                             font.pointSize:18
      //                                       id:text
      //                                       text: model.ParameterValue
      //                                       anchors.horizontalCenter: parent.horizontalCenter
      //                                       anchors.verticalCenter: parent.verticalCenter
      //                                       color:model.ParameterName
      //                                       font.family: "Arial"
      //                                       font.pointSize:18
                                         }
                                  }
                              }
      
                          }
      //                    add: Transition {
      //        //                NumberAnimation { property: "opacity"; from: 0; to: 1.0; duration: 400 }
      //        //                NumberAnimation { property: "scale"; from: 0; to: 1.0; duration: 400 }
      //                    }
      
                          displaced: Transition {
                              NumberAnimation { properties: "x,y"; duration: 1100;  easing.type: Easing.Linear }
                          }
      
                      focus: true
                      Component.onCompleted: {
      //                    listmodel.positionViewAtEnd()
                          titleRectanchor = titlexrect.left
                          titleRecttopanchor = titlexrect.top
                          listmodel.positionViewAtIndex(model.count - 1, ListView.Visible)
                      }
                      onCountChanged: {
                          listmodel.positionViewAtIndex(model.count - 1, ListView.Visible)
      
                      }
                      ScrollBar.horizontal: ScrollBar {
                          policy:ScrollBar.AlwaysOn
                          active: true
                      }
                  }
      
      G Offline
      G Offline
      GrecKo
      Qt Champions 2018
      wrote on 10 Nov 2020, 16:51 last edited by
      #2

      @Neethu-Antony Can you please fix your code snippet formating?
      use triple backtick to insert code in your post :

      ```
      code
      ```
      
      1 Reply Last reply
      0
      • N Offline
        N Offline
        Neethu Antony
        wrote on 10 Nov 2020, 17:11 last edited by
        #3

        @GrecKo ,
        Thank you for the suggestion.
        I Have updated the same.

        1 Reply Last reply
        0

        1/3

        10 Nov 2020, 15:09

        • Login

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