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. How to get default value in qml?
Forum Updated to NodeBB v4.3 + New Features

How to get default value in qml?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 54 Views
  • 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.
  • T Offline
    T Offline
    TomNow99
    wrote last edited by
    #1

    Hi,

    I have a qml component:

    In file XYZ.qml:
    
    Item {
       x: 10
       ...
    }
    

    Now in other file I would like to set his x-value:

    In file ABC.qml:
    
    Item {
       XYZ {
          x: someCondition ? 20 : defaultValue
       }
    }
    

    In this example defaultValue is 10. How can I do this? Here of course I know that x-value is 10, so I can write:

    x: someCondition ? 20 : 10
    

    but sometimes I don't know.

    J.HilkJ 1 Reply Last reply
    0
    • T TomNow99

      Hi,

      I have a qml component:

      In file XYZ.qml:
      
      Item {
         x: 10
         ...
      }
      

      Now in other file I would like to set his x-value:

      In file ABC.qml:
      
      Item {
         XYZ {
            x: someCondition ? 20 : defaultValue
         }
      }
      

      In this example defaultValue is 10. How can I do this? Here of course I know that x-value is 10, so I can write:

      x: someCondition ? 20 : 10
      

      but sometimes I don't know.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote last edited by J.Hilk
      #2

      @TomNow99

      Use an explicit binding, instead of a JS-Evauation

      Binding { target: xyzInstance; property: "x"; value: myTextField.text; when: someCondition; restoreMode: Binding.RestoreValue}
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      4

      • Login

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