Results 1 to 4 of 4

Thread: Hide the decimals in QDoubleSpinBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Location
    India
    Posts
    14
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Hide the decimals in QDoubleSpinBox

    Hi,
    Is it possible to hide decimals in QDoubleSpinBox if the values after the decimal are just zeros and show the decimal if the values are non zero. If the values after the decimal points are non zero then the precision should be 2.

    Thanks in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Hide the decimals in QDoubleSpinBox

    Try calling setDecimals() with '0' when the you only have 0's after the decimal point, and with 2 otherwise.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    vinodpaul (25th August 2011)

  4. #3
    Join Date
    Jun 2011
    Location
    India
    Posts
    14
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Hide the decimals in QDoubleSpinBox

    2.jpg1.jpgHi high_flyer , But if we setDecimals() with '0' ,then we won't be able to insert decimals if we want. The actual problem is that I have created a doubespinbox with dimension height 20 and width 45, but the numbers with precision 2 is not clearly visible within that box, and I cannot increase the box width also. I need to show the numbers clearly without increasing the width of the box. While changing the value of the spinbox, I noticed that the cursor position is changing from first position to last position and again back to first position alternatively. If the position of the cursor is after the number(2nd picture) then the number won't be shown properly.Is there any method by which I can keep the cursor at the first position itself .
    Last edited by vinodpaul; 25th August 2011 at 05:37.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Hide the decimals in QDoubleSpinBox

    Subclass and reimplement textFromValue().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QTableView set column Decimals
    By ottoshmidt in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2010, 05:00
  2. QDoubleSpinBox
    By prashant in forum Qt Programming
    Replies: 0
    Last Post: 7th October 2009, 16:30
  3. QDoubleSpinBox and QDoubleValidator
    By George Neil in forum Qt Programming
    Replies: 1
    Last Post: 26th June 2008, 00:36
  4. Subclass QDoubleSpinBox
    By SailinShoes in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 11:29
  5. QDoubleSpinBox
    By coderbob in forum Qt Programming
    Replies: 6
    Last Post: 20th March 2008, 11:30

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.