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. Two text area scroll with one Scroll Bar / view
Forum Updated to NodeBB v4.3 + New Features

Two text area scroll with one Scroll Bar / view

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 206 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.
  • AdithyaA Offline
    AdithyaA Offline
    Adithya
    wrote on last edited by
    #1

    I am trying to build a text compare editor and I need to scroll two text area with one scroll bar .

    ScrollView {
    id: _scrollview
    width: parent.width * 0.8
    height: parent.height

                    Row {
                        width: parent.width
                        height: parent.height
    
                        Rectangle {
                            id: _compareLeftBox
                            width: parent.width * 0.5
                            height: parent.height
                            color: "white"
    
                            TextArea {
                                id: _leftTextArea
                                anchors.fill: parent
                                readOnly: true
                                textFormat: TextEdit.RichText
                                wrapMode: TextArea.Wrap
                                //verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
                            }
                        }
    
                        Rectangle {
                            id: _compareRightBox
                            width: parent.width * 0.5
                            height: parent.height
                            color: "white"
    
                            TextArea {
                                id: _rightTextArea
                                anchors.fill: parent
                                readOnly: true
                                textFormat: TextEdit.RichText
                                wrapMode: TextArea.Wrap
                                //verticalScrollBarPolicy: Qt.ScrollBarAlwaysOff
                            }
                        }
                    }
                }
    
                ScrollBar.vertical: ScrollBar {
                    id: scrollBarY
                    orientation: Qt.Vertical
                    anchors.right: parent.right
                    anchors.top: parent.top
                    anchors.bottom: parent.bottom
    
                    // Bind ScrollBar position to ScrollView contentY
                    onPositionChanged: {
                        _leftTextArea.verticalScrollBar.position = scrollBarY.position
                        _rightTextArea.verticalScrollBar.position = scrollBarY.position
                    }
                }
        }
    

    I am not sure whats going wrong here

    1 Reply Last reply
    0
    • AdithyaA Offline
      AdithyaA Offline
      Adithya
      wrote on last edited by
      #2

      Found the solution by adding scroll view to both textarea and adding ScrollBar.vertical: property with a Scroll bar and assigning postions on onPositionChanged to both the scroll views when any one is scrolled

      1 Reply Last reply
      1
      • AdithyaA Adithya has marked this topic as solved on

      • Login

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