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

ScrollView with empty TextArea



  • Hi everyone!
    I am new to the QTForum and also pretty new to QML and QT Quick in general.

    At the moment, I am working on my very first project which is a lot of fun but I encounter difficulties from time to time. Right now, I have two problems:

    (1) the minor one: how can I activate mouse-click selection in the TextArea?

    (2) the major problem:
    I nested the TextArea inside a ScrollView to ensure scrolling whenever the text gets too long for the window. But since I want the user to enter text in the TextArea, the TextArea has to be empty at the start. That means that with the ScrollView one cannot click inside the TextArea and edit it.

    Here is the part of the code:

            ScrollView {
                id: view
                anchors.fill: parent
                anchors.bottomMargin: 40
    
                TextArea {
                    id: journalEntry
                    width: 80
                    height: 20
                    color: "#f2f2f2"
                    placeholderText: "Type your journal entry here"
                    anchors.left: parent.left
                    anchors.right: parent.right
                    anchors.top: parent.top
                    anchors.bottom: parent.bottom
                    anchors.fill: parent
                    font.pixelSize: 20
                    wrapMode: Text.WordWrap
                    font.bold: true
                    font.family: "Courier"
                    selectionColor: "#c55af2"
                    anchors.rightMargin: 20
                    anchors.leftMargin: 20
                    anchors.bottomMargin: 30
                    anchors.topMargin: 20
                    onTextChanged: if(text != "") return animationListExpand.running = true; else return animationListRetract.running = true
                    ScrollBar.vertical: ScrollBar { }
                    focus: true
                }
            }
    

    I hope you have a quick solution to this.

    Thank you very much and all the best,
    flo



  • hi @flo_g said in ScrollView with empty TextArea:

    (1) the minor one: how can I activate mouse-click selection in the TextArea?

    set selectByMouse property to true

    @flo_g said in ScrollView with empty TextArea:

    (2) the major problem:

    remove the line anchors.fill: parent in your TextArea,
    your are using width/height plus anchors.Top/Bottom/left/right plus anchors.fill to set the size of the TextArea, it is redundant, you do 3 times the same thing, do just one



  • @LeLev Thank you very much! This worked flawlessly!


Log in to reply