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
- Create a class called
customspinbox
with base classQSpinBox
(include QObject and QWidget). - Did following modifications to the
customspinbox
class:
#ifndef CUSTOMSPINBOX_H #define CUSTOMSPINBOX_H #include <QObject> #include <QWidget> #include <QSpinBox> class customspinbox : public QSpinBox { Q_OBJECT public: customspinbox(QWidget *parent =nullptr); }; #endif // CUSTOMSPINBOX_H
-
In the
mainwindow.ui
I added a SpinBox and promoted this to thecustomspinbox
class -
I speculate the next step will be to override
paintEvent
function to delete thetextBrowser
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
? - Create a class called
-
Hi,
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.