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

Set value via variable and function



  • I wanted to set size of object using function and resizing doesn't work

    It works

            object_value.width = Qt.binding(() => width)
            object_value.height = Qt.binding(() => height)
    

    It doesn't work -> why?

    object_value.setSize(mainWindow.width, mainWindow.height)
    
    
    
        function setSize(width, height)
        {
            main_multi_listview.width = Qt.binding(() => width)
            main_multi_listview.height = Qt.binding(() => height)
        }
    

    I tried use binding as parametr of function and it doesn't work too,

    object_value.setSize(Qt.binding(() => mainWindow.width), Qt.binding(() => mainWindow.height))
    


  • @PawlosCK said in Set value via variable and function:

    It doesn't work -> why?

    object_value.setSize(mainWindow.width, mainWindow.height)
    
    
    function setSize(width, height)
    {
        main_multi_listview.width = Qt.binding(() => width)
        main_multi_listview.height = Qt.binding(() => height)
    }
    

    No this can not work!
    You function did not make sense to me.
    The parameters are copies, not references so it can not work as you expect.

    I would change to function to:

     object_value.setSize(mainWindow);
    
    function setSize(item) {
        main_multi_listview.width = item.with
        main_multi_listview.width = Qt.binding(() => item.with)
        main_multi_listview.height = item..height
        main_multi_listview..height = Qt.binding(() => item..height)
    }
    

Log in to reply