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. Custom expression for QDoubleSpinBox
Qt 6.11 is out! See what's new in the release blog

Custom expression for QDoubleSpinBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 728 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.
  • G Offline
    G Offline
    Gaetano03
    wrote on last edited by
    #1

    Hello,

    I would need to change the format of QDoubleSpinBox in order to have a dot to separate integer from fractional part and commas to separate the integer part. E.g. if i have 1000000.456 where 1000000 is the integer part and 456 the decimal, I would like it to be formatted as

    1,000,000.456
    

    Would it be possible on a QDoubleSpinBox without subclassing it?
    If I need to subclass it, is there a way to use it also as a QCustomBox model for the Qt designer in Qt Creator, since I am using Qt creator to generate complex widgets which include these spin boxes?

    Thanks for your help

    JonBJ 1 Reply Last reply
    0
    • G Gaetano03

      Hello,

      I would need to change the format of QDoubleSpinBox in order to have a dot to separate integer from fractional part and commas to separate the integer part. E.g. if i have 1000000.456 where 1000000 is the integer part and 456 the decimal, I would like it to be formatted as

      1,000,000.456
      

      Would it be possible on a QDoubleSpinBox without subclassing it?
      If I need to subclass it, is there a way to use it also as a QCustomBox model for the Qt designer in Qt Creator, since I am using Qt creator to generate complex widgets which include these spin boxes?

      Thanks for your help

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Gaetano03
      Every hit I can see indicates that you do need to subclass QDoubleSpinBox to control its text format (QString textFromValue()), e.g. https://stackoverflow.com/questions/54295639/how-to-set-qdoublespinbox-to-scientific-notation or https://stackoverflow.com/questions/27332700/how-to-change-text-format-of-qdoublespinbox .

      QCustomBox model

      Don't know what that is. You could have it as a Qt Designer custom widget to use in Designer, but for this simple subclassing just using Designer's Promote... feature is simpler and should be adequate.

      1 Reply Last reply
      2
      • G Offline
        G Offline
        Gaetano03
        wrote on last edited by
        #3

        Seems like I achieved it using this

        https://stackoverflow.com/questions/9274884/qspinbox-thousand-separator

        if this can be of help to others.

        Thanks!

        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