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

What determines the difference?



  • Hi, I am a beginner, It could be silly question, but I didn't find the reason.
    Please, any comments, Thank you.

    I was following an qml-example.

    The example code and my code are exactly the same, but I found a difference in output.

    When resizing the window with a mouse, in the example the logs are logged via the onWidthChanged handler, but not in my code.

    I checked code again even QtQuick version and debugger version.

    Can you guess what makes this difference ?

    ------ code

    Rectangle {
        id: root
        width: 320
        height: 440
        onWidthChanged: console.log('width changed : ' + width)
        onHeightChanged: console.log('height changed : ' + height)
    }
    

  • Lifetime Qt Champion

    Hi @hslee_6560,

    can you show your code?



  • There is not enugh code. But if your Rectangle doesn't attached to a root window via anchors or you have no any bindings to width/height property you will never get any changes when resizing window by mouse.
    Working fine example:

    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle {
            anchors.centerIn: parent
            width:  parent.width * 0.5
            height: parent.height * 0.5
            onWidthChanged: console.log('width changed : ' + width)
            onHeightChanged: console.log('height changed : ' + height)
            color: "teal"
        }
    }
    

Log in to reply