I need a Spin Control. Can I make a spin box without the text box?
-
Hello,
I want to have the equivalent of a Windows spin control ie. just the spinner arrows with no text box attached. I have done this using a very small scrollbar which works fine on Windows but it does not work on the Mac because there are no arrows on the Mac scrollbars??
The spin box has the arrows on the Mac so Is there a way to kill the text box an just have spinner arrows?
Can anyone recommend another way of implementing this which does not require doing everything myself from basic widgets?Or, is there a way to display the arrows on the Mac?
I will be very grateful for any other suggestions.
Many thanks
-
You can use stylesheet & set arrows with icons suitable for Mac.
-
what happens when you do the following?
@
mySpinBox->lineEdit()->hide();
@ -
Thanks for the suggestion raven-worx.
I found that the edit box is a protected member of QAbstractSpinBOx so its hide method cannot be accessed from QSpinBox.
-
Thank you for your suggestion mehrdadsilver.
I will look into that but I am not sure how I can style buttons that don't already exist on the control??
can you please show me how that would look in a style sheet?
Thanks
-
[quote author="kenchan" date="1379923919"]Thanks for the suggestion raven-worx.
I found that the edit box is a protected member of QAbstractSpinBOx so its hide method cannot be accessed from QSpinBox.
[/quote]
Yes, you need to subclass it then.
@
MySpinBox::MySpinBox(QWidget* parent)
: QSpinBox(parent)
{
this->lineEdit()->hide();
}
@I#m not sure that it will work as expected, but worth a try IMHO.
-
I tried to subclass it but I get the same compiler error because the lineEdit object is a protected member of QAbstractSpinBox.
@
class MySpinBox : public QSpinBox
{
Q_OBJECTpublic:
MySpinBox(QWidget* parent);
};MySpinBox::MySpinBox(QWidget* parent)
: QSpinBox(parent)
{
lineEdit()->hide();
}
@error: C2248: 'QAbstractSpinBox::lineEdit' : cannot access protected member declared in class 'QAbstractSpinBox'
Is there another way to do this?
-
Are you sure you are using your MySpinBox class at all? Your code is correct, thus it should definitely work.
Does the C2248 compiler error really come from the line in the MySpinBox constructor?!
-
Sorry my mistake. I was able to get rid of the compiler error but not the line edit. It will not hide and I can't change the geometry to make it smaller.
-
Hello Again,
This one looks like a dead and. I don't think I am going to be able to hide the line edit without subclassing QAbstractSpinBox or something. My other alternative is to make my own control to do this which I don't have time to do right now.
If anyone has any more ideas they will be very much appreciated.
Thanks again.
-
Hello
Just signed up here because I have the same issue.
So first of all, hello world ;-)This thread is quite old, but is it still not possible to create a sole spin control without text field?
Cheers
delos -
@delos
I don't believe the preceding discussion necessarily exhausted all the possibilities.I would try to do it via stylesheet and hiding of the line edit, if that's possible. I'm sorry but I am too tired to look up how you address the line edit this way, you'll have to find the refence section in the Qt docs for stylsheets & widgets.
Or, since there is https://doc.qt.io/qt-5/qabstractspinbox.html#setLineEdit, even if you can't hide the inbuilt one I would have thought this really ought allow you control over your own line edit.
-
Thanks for the quick answer. Since QLinedit seems to be protected, I don't have access. Furthermore, I don't find away how to e.g. set the width of the text box.
Anyway, I'll try with style sheets. Since I just started with Qt, it will take a while. Whenever I found a solution I will report on it.Cheers
delos