Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

ScrollView not working with TextEdit?



  • It worked with a 1.x version of the libraries, but 2.x is not letting me use scroll bars correctly. If the text goes off the end of the page it does not allow me to scroll.

    import QtQuick 2.12
    import QtQuick.Controls 2.5
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Scroll")
    
        ScrollView {
            anchors.fill: parent
    
            TextEdit {
                width: parent.width
    
                textFormat: Text.PlainText
                focus: true
                selectByMouse: true
    
                text: "asdf\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nasdf"
            }
        }
    }
    


  • Updated with scroll bar that worked with other objects like ListView:

    import QtQuick 2.12
    import QtQuick.Controls 2.12
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Scroll")
    
        ScrollView {
            anchors.fill: parent
    
            ScrollBar.vertical: ScrollBar {
                id: verticalBar
                anchors.top: parent.top
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                hoverEnabled: true
                active: hovered || pressed
    
                property bool showIt: hovered || pressed
    
                background: Rectangle {
                    implicitWidth: 25
                    implicitHeight: 40
                    radius: 5
                    color: verticalBar.showIt ? "grey" : "transparent"
                }
    
                contentItem: Item {
                    implicitWidth: 25
                    implicitHeight: 40
                    Rectangle {
                        anchors.fill: parent
                        anchors.topMargin: 6
                        anchors.leftMargin: 4
                        anchors.rightMargin: 4
                        anchors.bottomMargin: 6
                        radius: 10
                        color: verticalBar.showIt ? "#424246" : "transparent"
                    }
                }
            }
    
            TextEdit {
                width: parent.width
    
                textFormat: Text.PlainText
                focus: true
                selectByMouse: true
    
                text: "asdf\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nasdf"
            }
        }
    }
    


  • Gahhhh! It looks like I should be using a TextArea now:
    https://doc.qt.io/archives/qt-5.11/qml-qtquick-controls2-textarea.html



  • @fcarney Yes, this came up recently:

    https://forum.qt.io/topic/106020


Log in to reply