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.


  • Moderators

    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


  • Moderators

    [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_OBJECT

    public:
    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?


  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.