Results 1 to 11 of 11

Thread: QSpinBox or QLabels

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QSpinBox or QLabels

    I like the ability to add a suffix to a QSpinBox and do not know how to do what I am proposing to do. When I move the mouse over a QGLWidget I need to be able to display the coordinates of the mouse as they move. I want to be able to update the value while keeping the label of the units next to the number, much like the suffix does for the QSpinBox. Is there a way to make the QSpinBox uneditable and to remove the arrows from it...basically a labal with a suffix? Or is there an efficient way to layout 2 labels so the suffix is always correctly spaced from the mouse coordinate while being right aligned to the window? Or would it just be easiest to use one label and always add the suffix manually even though it will never change? Thanks!

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

    Default Re: QSpinBox or QLabels

    It would be easier to use a label.

  3. #3
    Join Date
    Nov 2007
    Posts
    89
    Thanked 21 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSpinBox or QLabels

    Try this way:
    Qt Code:
    1. box.setButtonSymbols(QAbstractSpinBox::NoButtons);
    2. box.setReadOnly(true);
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to bender86 for this useful post:

    ToddAtWSU (27th November 2007)

  5. #4
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Cool Re: QSpinBox or QLabels

    Quote Originally Posted by bender86 View Post
    box.setButtonSymbols(QAbstractSpinBox::NoButtons);[/CODE]
    Where do you see QAbstractSpinBox::NoButtons? All I see is QAbstractSpinBox::UpDownArrows and QAbstractSpinBox::PlusMinus. I would imagine this worked but I do not see this anywhere in the docs. Thanks for your further clarification.

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSpinBox or QLabels

    Quote Originally Posted by ToddAtWSU View Post
    Where do you see QAbstractSpinBox::NoButtons?
    It was introduced in Qt 4.3.
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    ToddAtWSU (27th November 2007)

  8. #6
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox or QLabels

    Quote Originally Posted by jpn View Post
    It was introduced in Qt 4.3.
    Thanks. I followed the other link and it was in 4.2. I am still unfortunately at 4.1. I know I need to upgrade soon...but can't right this minute. Thanks!

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

    Default Re: QSpinBox or QLabels

    A read only spinbox yields no advantage over a regular line edit. The text is assembled every time you change it anyway, so there are no performance benefits of using QSpinBox over QLineEdit. And if you want to display something, you should use QLabel or friends, not QSpinBox or QLineEdit.

  10. #8
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox or QLabels

    Quote Originally Posted by wysota View Post
    A read only spinbox yields no advantage over a regular line edit. The text is assembled every time you change it anyway, so there are no performance benefits of using QSpinBox over QLineEdit. And if you want to display something, you should use QLabel or friends, not QSpinBox or QLineEdit.
    The only advantage I am looking for is so I don't have to remember to add the label to my QLabel every time I change it. With the SpinBox's suffix feature, this allows me to just change the value and never worry about forgetting to add the suffix at the end of my label.

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

    Default Re: QSpinBox or QLabels

    What kind of argument is this? Ever heard of functions or methods?

  12. #10
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox or QLabels

    haha...yeah I just never think of writing functions for something so simple like that...i admit a bad argument and I think i will just write a simple function!

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

    Default Re: QSpinBox or QLabels

    My point is that you should use proper components for proper tasks. For example you shouldn't use a combobox if you have only two choices - use radio buttons or a checkbox instead. If you want to display text, don't use input widgets. These are rules of good ui design.

Similar Threads

  1. eventFilter and clicking inside QSpinBox
    By T4ng10r in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2007, 22:02
  2. QSpinBox and setStylesheet problem
    By Ace-X in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2007, 12:21
  3. QSpinBox with checkbox
    By :db:sStrong in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2007, 14:22
  4. float value to Qspinbox
    By nErnie in forum Qt Programming
    Replies: 6
    Last Post: 17th October 2006, 09:16
  5. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 09:12

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.