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

how to set offset in layout



  • I have a GridLayout in which I defined two columns. Left column should be spaces equal to left column length. I tried to create a white color rectangle which would act as an empty area like this:

    GridLayout {
            columns: 2
            // Trying to set rectangle as an offset for Label
            Rectangle {
                width: parent.width / 2
                height: parent.height
            }
    
            Label {
                text: "some text"
            }
        }
    

    That didn't work. So how would I go about creating left column as an offset for right column ?



  • @Ahti hi

       Rectangle {
                   // width: parent.width / 2
                    Layout.preferredWidth: parent.width / 2
                   // height: parent.height
                    Layout.preferredHeight: parent.height
                    color: "grey"
                }
    


  • @LeLev I was expecting there would be some other option besides creating a rectangle.



  • @Ahti misunderstood your question,see if this helps

    GridLayout {
                anchors.fill: parent
                columns: 2
    
    
                Label {
    
                    text: "some text"
                    Layout.preferredWidth: parent.width / 2
                    Layout.alignment: Qt.AlignRight
                }
            }
    

Log in to reply