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



  • 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.



  • 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) })
    }
    

    }
    @



  • Thank you :) got it to work using:

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

    :)



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.