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. Using ColumnLayout with a ScrollView
Forum Updated to NodeBB v4.3 + New Features

Using ColumnLayout with a ScrollView

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 911 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.
  • Q Offline
    Q Offline
    qcoderpro
    wrote on last edited by
    #1

    Hi all,

    I'm going to use a TextArea inside a ScrollView within a CoumnLyout the following way which must be OK but doesn't look that way! Any reason, please?

    gfh.PNG

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by Markkyboy
      #2

      Try this;

      import QtQuick 2.15
      import QtQuick.Window 2.15
      import QtQuick.Controls 2.15
      
      Window {
          width: 640
          height: 480
          visible: true
          color: "lightblue"
          title: qsTr("qcoderpro")
      
          Column {
              Label {
                  text: "Input text below"
                  anchors.horizontalCenter: parent.horizontalCenter
              }
              ScrollView {
                  width: 200; height: width; clip: true
                  TextArea { text: "QCODERPRO"; selectionColor: "lightblue"; font.pixelSize: 224 }
              }
          }
      }
      
      

      To try and clarify the differences between Column and ColumnLayout, have a read of the second comment from Gianluca; https://forum.qt.io/topic/47844/solved-column-vs-columnlayout-bug-or-feature/3

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      Q 1 Reply Last reply
      1
      • MarkkyboyM Markkyboy

        Try this;

        import QtQuick 2.15
        import QtQuick.Window 2.15
        import QtQuick.Controls 2.15
        
        Window {
            width: 640
            height: 480
            visible: true
            color: "lightblue"
            title: qsTr("qcoderpro")
        
            Column {
                Label {
                    text: "Input text below"
                    anchors.horizontalCenter: parent.horizontalCenter
                }
                ScrollView {
                    width: 200; height: width; clip: true
                    TextArea { text: "QCODERPRO"; selectionColor: "lightblue"; font.pixelSize: 224 }
                }
            }
        }
        
        

        To try and clarify the differences between Column and ColumnLayout, have a read of the second comment from Gianluca; https://forum.qt.io/topic/47844/solved-column-vs-columnlayout-bug-or-feature/3

        Q Offline
        Q Offline
        qcoderpro
        wrote on last edited by
        #3

        @Markkyboy

        Probably I need to use implicitWidth and implicitHeight for the ScrollView.

        1 Reply Last reply
        0
        • MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on last edited by
          #4

          probably?, meaning what exactly?

          Don't just sit there standing around, pick up a shovel and sweep up!

          I live by the sea, not in it.

          Q 1 Reply Last reply
          0
          • MarkkyboyM Markkyboy

            probably?, meaning what exactly?

            Q Offline
            Q Offline
            qcoderpro
            wrote on last edited by qcoderpro
            #5

            @Markkyboy
            For

            Column {
                    anchors.fill: parent
                    Label { text: " Type your text below" }
                    spacing: 10
            
                    ScrollView {
                        width: parent.width / 2
                        height: width / 6
                        clip: true
                        TextArea {
                            wrapMode: "WordWrap"
                        }
                    }
                }
            

            I get the error: QML TextArea: Binding loop detected for property "implicitHeight" when the entered text exceeds the width boundary of the textArea.

            MarkkyboyM 1 Reply Last reply
            0
            • Q qcoderpro

              @Markkyboy
              For

              Column {
                      anchors.fill: parent
                      Label { text: " Type your text below" }
                      spacing: 10
              
                      ScrollView {
                          width: parent.width / 2
                          height: width / 6
                          clip: true
                          TextArea {
                              wrapMode: "WordWrap"
                          }
                      }
                  }
              

              I get the error: QML TextArea: Binding loop detected for property "implicitHeight" when the entered text exceeds the width boundary of the textArea.

              MarkkyboyM Offline
              MarkkyboyM Offline
              Markkyboy
              wrote on last edited by
              #6

              @qcoderpro - I cannot reproduce your error. It compiles as I expected, as does my code example., odd indeed.

              Perhaps to try running qmake before building and clean the build as well , as you are not referencing implicitHeight in your code, so I'm not quite sure where your error is coming from. I sometimes experience errors that do relate to a previous project, but usuall y this occurs with I have several projects open in SDK.

              Don't just sit there standing around, pick up a shovel and sweep up!

              I live by the sea, not in it.

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lemons
                wrote on last edited by
                #7

                You have to tweak the layout behavior to match your requirements.
                Per default, all available space will be distributed equally between all children.

                import QtQuick.Window 2.15
                import QtQuick 2.15
                import QtQuick.Controls 2.15
                import QtQuick.Layouts 1.12
                
                Window {
                    width: 500
                    height: 400
                    visible: true
                
                    ColumnLayout {
                        // set outer bounderies for layout, not in the children
                        anchors.fill: parent
                        anchors.rightMargin: parent.width / 2
                
                        spacing: 10
                        anchors.margins: 10
                
                        Label {
                            Layout.fillWidth: true
                            // disable taking more height then required
                            Layout.fillHeight: false
                            color: "darkgray"
                            text: qsTr("Type your text below")
                            wrapMode: "Wrap"
                            font.pointSize: 14
                        }
                
                        ScrollView {
                            Layout.fillWidth: true
                            // automatically fill empty height
                            // > if you would set this to TRUE for multiple children, the available
                            // space will be equally distributed between them
                            Layout.fillHeight: true
                            TextArea {
                                // you don't need width&height or anchors.fill here
                                // TextArea automatically fills ScrollView
                                background: Rectangle {
                                    color: "red"
                                }
                
                                // use Wrap instead of WordWrap to avoid long single
                                // words to overflow
                                // > Wrap automatically prefers WordWrap
                                wrapMode: "Wrap"
                                padding: 10
                            }
                        }
                    }
                }
                
                
                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