PDA

View Full Version : QSpinBox or QLabels



ToddAtWSU
27th November 2007, 16:50
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!

wysota
27th November 2007, 16:58
It would be easier to use a label.

bender86
27th November 2007, 17:01
Try this way:

QSpinBox box;
box.setButtonSymbols(QAbstractSpinBox::NoButtons);
box.setReadOnly(true);

ToddAtWSU
27th November 2007, 19:26
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.

jpn
27th November 2007, 19:30
Where do you see QAbstractSpinBox::NoButtons?
It was introduced in Qt 4.3.

ToddAtWSU
27th November 2007, 20:36
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!

wysota
27th November 2007, 20:41
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.

ToddAtWSU
27th November 2007, 20:48
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.

wysota
27th November 2007, 20:50
What kind of argument is this? Ever heard of functions or methods? :)

ToddAtWSU
27th November 2007, 20:53
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! :)

wysota
27th November 2007, 21:10
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.