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. Control width of Text Input in QML SpinBox
Forum Update on Monday, May 27th 2025

Control width of Text Input in QML SpinBox

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 1.1k 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.
  • R Offline
    R Offline
    RadiumBall
    wrote on last edited by RadiumBall
    #1

    Hi,
    I want to control the width of Text Input in QML SpinBox. We see that as we type in more characters the width of Text Input increases to accommodate the characters. We do not want this width increase but rather have the characters elided.

    Please help.

    1 Reply Last reply
    0
    • qtprogrammer123Q Offline
      qtprogrammer123Q Offline
      qtprogrammer123
      wrote on last edited by
      #2

      I understand you? You wonna set maximum width of TextInput with SpinBox, but field width should only grow when text gets longer?

              SpinBox{
                  id: widthSpin
              }
      
              TextInput {
                  id: textField
      
                  property int textMaxWidth: widthSpin.value
                  property int textWidth: textMetrics.width
      
                  width: textWidth < textMaxWidth ? textWidth : textMaxWidth
      
                  TextMetrics {
                      id: textMetrics
      
                      font: textField.font
                      text: textField.text
      
                  }
              }
      

      Ofc you should add elide, max / min for widthSpin etc, property for minimum field length will be good idea too - if you set width to 0 it will look bad.

      Mam moc jak Harry Potter, w zębach mogę przenieść hotel.

      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