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

value of the width



  • Hello all

    What is the value of the width? which is between stars
    parent.width i understand, it takes Window width
    import QtQuick 2.12
    import QtQuick.Window 2.12

    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Rectangle{
            id: root
            
            width: (parent.width-***width***)/2;
            height: 240;
    
            color: "#4A4A4A"
    

    Regards,
    Jasur


  • Moderators

    @Jasur said in value of the width:

    What is the value of the width?

    What happens when you run your code?



  • @JKSH Code runs without any errors, this example i taked from book https://qmlbook.github.io in the page: 32, and in this example from "parent.width" it subtracting "width", in the book it doesn't written what is the value of the "width". That is why i want to understand

    Regards,
    Jasur


  • Moderators

    That width comes from the Rectangle. Unless I get it wrong, it is a binding loop and QML engine will warn about it in console output.


  • Moderators

    @Jasur said in value of the width:

    this example i taked from book https://qmlbook.github.io in the page: 32, and in this example from "parent.width" it subtracting "width", in the book it doesn't written what is the value of the "width". That is why i want to understand

    The book's example has x: (parent.width - width)/2 which is fine. It means, "This Rectangle's x value shall equal the parent's width minus this Rectangle's width, all divided by two".

    However, the code you posted above is not fine: width: (parent.width - width)/2 means "This Rectangle's width value shall equal the parent's width minus this Rectangle's width, all divided by two". With this code, it is impossible to calculate this Rectangle's width.

    Code runs without any errors

    When I run your code with Qt 5.14.1, I see the following error message in Qt Creator's Application Output pane:

    qrc:/main.qml:10:2: QML Rectangle: Binding loop detected for property "width"


  • @JKSH thank you, now i understand

    "This Rectangle's x value shall equal the parent's width minus this Rectangle's width, all divided by two".
    

    about my code, i am using Qt 5.12, maybe that is why i don't see any error and maybe i disabled LD_LIBRARY_PATH in the project, because of swrast, but tottaly it runs perfect.

    Thank you very much for explaining.

    Regards,
    Jasur



  • @sierdzio Thank you for explaining


Log in to reply