Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Displaying a QString in a QSpinBox
Qt 6.11 is out! See what's new in the release blog

Displaying a QString in a QSpinBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.2k 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.
  • M Offline
    M Offline
    mulfycrowh
    wrote on last edited by
    #1

    Hi

    I have a QSpinBox.
    I would like to display a QString while clicking the arrows, instead displaying value.
    I also need the value to call a slot.
    I tried setSpecialValueText but it obviously only runs when value equals minimum.
    Thanks

    jsulmJ 1 Reply Last reply
    0
    • M mulfycrowh

      Hi

      I have a QSpinBox.
      I would like to display a QString while clicking the arrows, instead displaying value.
      I also need the value to call a slot.
      I tried setSpecialValueText but it obviously only runs when value equals minimum.
      Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @mulfycrowh said in Displaying a QString in a QSpinBox:

      QSpinBox

      Hi!
      Your question is really unclear. What QString do you want to show?
      If you want to show some strings instead of numbers then you need to subclass QSpinBox and override valueFromText and textFromValue as explained in the documentation.
      "I also need the value to call a slot." - what does this mean? Do you want to call a slot each time the value is changed? If so then just connect one of the valueChanged(...) signals to your slot (http://doc.qt.io/qt-5/qspinbox.html).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • JohanSoloJ Offline
        JohanSoloJ Offline
        JohanSolo
        wrote on last edited by
        #3

        @mulfycrowh said in Displaying a QString in a QSpinBox:

        I have a QSpinBox.
        I would like to display a QString while clicking the arrows, instead displaying value.
        I also need the value to call a slot.
        I tried setSpecialValueText but it obviously only runs when value equals minimum.
        Thanks

        If you re-implement your own spinbox class, I guess this is possible as @jsulm said. But simpler than that might be to use QComboBox.

        `They did not know it was impossible, so they did it.'
        -- Mark Twain

        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