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. Is it possible to have two different tableviews scroll according to eachother? [solved]
Forum Updated to NodeBB v4.3 + New Features

Is it possible to have two different tableviews scroll according to eachother? [solved]

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 943 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.
  • S Offline
    S Offline
    skammers
    wrote on last edited by
    #1

    I have two different tableviews containing QStrings. I need them to scroll according to eachother so they are always on the same height in the content. Is this possible? If not, what kind of an other approach could I use?
    Im kind of new to this, so please help.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JvdGlind
      wrote on last edited by
      #2

      In QML:

      @import QtQuick 2.2
      import QtQuick.Controls 1.2
      import QtQuick.Window 2.1

      Window {
      visible: true
      width: 360
      height: 360

      ListModel {
          id: someNumbersModel
      }
      
      function valueChanged(value) {
          firstTableView.__verticalScrollBar.value = value;
          secondTableView.__verticalScrollBar.value = value;
      }
      
      TableView {
          id: firstTableView
      
          anchors.top: parent.top;
          anchors.left: parent.left;
          anchors.right: parent.horizontalCenter;
          anchors.bottom: parent.bottom;
      
          TableViewColumn{ role: "location"  ; title: "Location" ; width: 100 }
          model: someNumbersModel
      
          flickableItem.onContentYChanged: secondTableView.flickableItem.contentY = flickableItem.contentY
          flickableItem.onContentXChanged: secondTableView.flickableItem.contentX = flickableItem.contentX
      }
      TableView {
          id: secondTableView
      
          anchors.top: parent.top;
          anchors.left: parent.horizontalCenter;
          anchors.right: parent.right;
          anchors.bottom: parent.bottom;
      
          TableViewColumn{ role: "location"  ; title: "Location" ; width: 100 }
          model: someNumbersModel
      
          flickableItem.onContentYChanged: firstTableView.flickableItem.contentY = flickableItem.contentY
          flickableItem.onContentXChanged: firstTableView.flickableItem.contentX = flickableItem.contentX
      }
      
      property int a;
      Component.onCompleted: {
          for(a = 0 ; a < 100 ; a++)
              someNumbersModel.append({ "location": String(a) })
      }
      

      }
      @

      Jeffrey VAN DE GLIND
      Principle Consultant @ Nalys
      www.nalys-group.com

      1 Reply Last reply
      0
      • S Offline
        S Offline
        skammers
        wrote on last edited by
        #3

        Thank you :) got it to work using:

        flickableItem.onContentYChanged: secondTableView.flickableItem.contentY = flickableItem.contentY
        flickableItem.onContentXChanged: secondTableView.flickableItem.contentX = flickableItem.contentX

        :)

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

          No problem :). Please at [solved] to the title for the other readers.

          Jeffrey VAN DE GLIND
          Principle Consultant @ Nalys
          www.nalys-group.com

          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