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. SpinBox with percentage symbol
Forum Updated to NodeBB v4.3 + New Features

SpinBox with percentage symbol

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 932 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by
    #1

    Hi I want a SpinBox that accepts percentage as its input. And I want it in QtQuick.Controls version 2.2 in the previous version you could do it with suffix or prefix i guess but that is removed in 2.2 version how would I do it in 2.2 ?

    what is a signature ?? Lol

    J.HilkJ 1 Reply Last reply
    0
    • AhtiA Ahti

      Hi I want a SpinBox that accepts percentage as its input. And I want it in QtQuick.Controls version 2.2 in the previous version you could do it with suffix or prefix i guess but that is removed in 2.2 version how would I do it in 2.2 ?

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

      @Ahti
      by reimplementing textFromValue and valueFromText

      On how to do that, there's a very well and detailed example in the documentary:

      https://doc.qt.io/qt-5/qml-qtquick-controls2-spinbox.html#custom-values

      It is for making a doublespinbox, but you should be able to adapt that to a prefix only :)


      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
      1
      • Shrinidhi UpadhyayaS Offline
        Shrinidhi UpadhyayaS Offline
        Shrinidhi Upadhyaya
        wrote on last edited by
        #3

        Hi @Ahti , if you trying to customize the contentItem of the Spinbox then i guess you can also use the contentItem property and add "%" to the Text.

        Sample Code:-

        SpinBox {
            id: control
            value: 20
        
            contentItem: Text {
                z: 2
                text: control.value + "%"
                font: control.font
                color: "green"
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
            }
        }
        

        Sample Output:-

        0_1560749150869_1d68b40b-7dbf-41eb-9fb2-664819b41d0b-image.png

        Shrinidhi Upadhyaya.
        Upvote the answer(s) that helped you to solve the issue.

        1 Reply Last reply
        3

        • Login

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