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

Layouts in ScrollViews



  • Hello,

    I have some Problems using Layouts in Scrollviews, probably more on how ScrollViews in general work.

    My Layout always has the width and height of 0, although the ScrollView has something around 1300x700 (which is my Laptop screen - some margins ...)

    import QtQuick 2.10
    import QtQuick.Controls 2.3
    import QtQuick.Layouts 1.3
    
    ScrollView {
      id: root
      anchors.fill: parent
    
      RowLayout {
        anchors.fill: parent
    
        Rectangle {
          Layout.fillWidth: true
          Layout.fillHeight: true
          color: "blue"
        }
        Component.onCompleted: { console.log(width); console.log(height) }
      }
      Component.onCompleted: { console.log(root.width); console.log(root.height) }
    }
    
    

    It would be great if anyone could explain me, why the width and height are 0 and therefore the rectangle does not fill the screen.

    Just to explain my goal. In the End, there should be two Components inside the ScrollView next to each other filling the screen width, but having only the height as necessary (implicit height).
    -> A Textarea with lineNumbers ... I tried several possibilities and one worked, but it wasn't perfect. In General, the difficulty is that the TextArea has to be attached to a Flickable or directly inside a ScrollView for autoscroll and things like this.

    From the docs:
    " A TextArea that is placed inside a ScrollView does the following:

    Sets the content size automatically
    Ensures that the background decoration stays in place
    Clips the content "

    -> I don't know how to achieve this behaviour if there are lineNumbers next to the Textarea (which of course should scroll automatically too).

    Thanks for any advice!

    Greetings Leon


Log in to reply