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

Not Able to align the rectangles



  • Hi All,

    I have one problem in vertically aligning the rectangles.

    @import QtQuick 2.0
    import "qrc:/gui"

    Rectangle {
    id: main_screen
    width: 480
    height: 700
    color: "black"

    Rectangle {
        id: top_screen
        anchors.centerIn:  top_screen.horizontalCenter
    
        ToggleButton {
            id: settings_button
            source: "qrc:/icons/cavitron_logo.png"
            x: 180
            property int state: 0
            property string prevScreen: ""
    
            onButtonLongPressed: {
                if (state == 0) {
                    prevScreen = loader.source
                    loader.source = "qrc:/gui/SettingsScreen.qml"
                    state = 1
                }
                else if (state == 1) {
                    loader.source = prevScreen
                    state = 0
                }
            }
        }
    }
    
    Rectangle {
        id: middle_screen
        anchors.top: top_screen.bottom
        anchors.centerIn: parent
    
        Loader {
            id: loader
            anchors.centerIn: middle_screen
            source: "qrc:/gui/ScaleScreen.qml"
        }
    
        Connections {
            target: loader.item
            onShowScreen: loader.source = link
        }
    }
    
    Rectangle {
        id: lock_screen // bottom screen
        anchors.top: middle_screen.bottom
    
        Image {
            source: "qrc:/icons/lock.png"
        }
    }
    

    }
    @

    this last rectangle is always coming in the middle of the middle of the screen on left side and not coming in bottom as intended.Can anybody help me in solving this issue.?

    Thanks


  • Moderators

    Hi,

    Try anchoring it to bottom of your main_screen.
    @
    anchors.bottom: main_screen.bottom
    @


Log in to reply