Qt World Summit: Register Today!

How to modify QSpinBox appearance

  • Hi All,

    I have got a basic question. How to sublcass a Qt object to make some modification in the appearance?

    For ex. I need to modify the standard QSpinBox just with the increment/decrement buttons without the value display:


    Even though I came across the keyword "sublcass" an object, I never understood systematic way of doing this. It will be very helpful if someone shows the step-by-step procedure to subclass a standard QSpinBox. I started with the following steps, correct me if I'm wrong

    1. Create a class called customspinbox with base class QSpinBox (include QObject and QWidget).
    2. Did following modifications to the customspinbox class:
    #include <QObject>
    #include <QWidget>
    #include <QSpinBox>
    class customspinbox : public QSpinBox
      customspinbox(QWidget *parent =nullptr);
    #endif // CUSTOMSPINBOX_H
    1. In the mainwindow.ui I added a SpinBox and promoted this to the customspinbox class

    2. I speculate the next step will be to override paintEvent function to delete the textBrowser or similar object which displays the spinbox value. But I don't know how to do this.

    can you show me how to get rid of the display part of the QSpinBox?

  • Lifetime Qt Champion


    Wouldn't it be simpler to create a custom widget with these two buttons ?
    It looks like you are about to make your life more complicated than needed.

Log in to reply