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. Add double property as alias to text property
Qt 6.11 is out! See what's new in the release blog

Add double property as alias to text property

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 930 Views 1 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.
  • R Offline
    R Offline
    Rem-Kolomna
    wrote on last edited by
    #1

    Hi! I defined my own component, FloatField that is essentially a TextField with DoubleValidator. I want to implement a value property that should be equal to text property converted to double. I implemented updating value as text changed. But how can I update text then user changed value?

    TextField {
        property double value: 0
        validator: DoubleValidator { }
        focus: true
        text: "0"
        onAccepted: value = text
    }
    
    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rem-Kolomna
      wrote on last edited by
      #2

      The asnwer turns out to be as simple as:

      TextField {
          property double value: 0
          validator: DoubleValidator { }
          focus: true
          text: "0"
          onAccepted: value = text
          onValueChanged: text = value
      }
      
      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