Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set value via variable and function
Qt 6.11 is out! See what's new in the release blog

Set value via variable and function

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 349 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PawlosCK
    wrote on last edited by PawlosCK
    #1

    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))
    
    1 Reply Last reply
    0
    • KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @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)
      }
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved