Important: Please read the Qt Code of Conduct -

Making custom button widget

  • Hi All,

    I need a custom button widget as shown below:


    I need to make this as reusable throughout my project. Is there any documentation detailing procedure to make custom button widgets?

    Thank you

  • Lifetime Qt Champion

    But is that not more like a QSlider ?
    And not a button?

    In any case, you would inherit from the base class you want and override virtual function or add new functions to make it do what you want. Sample is not related to slider/button. just example.

      #include <qwidget.h>
        class Vcr : public QWidget
            Vcr( QWidget *parent = 0, const char *name = 0 );
            ~Vcr() {}
            void rewind();
            void play();
            void next();
            void stop();

    However, for such slider thingy , would it not be easier to simply make a composite widget.
    One that is made of several widgets ?

    alt text
    and then use stylesheet and images to make it look like the image.

    However, if u really want the value to show on the Sliders handle, then you have to subclass
    QSlider and its paintEvent, to draw the the value on top. its not possible via stylesheets.

  • Lifetime Qt Champion


    Isn't that basically the same question as this thread ?

  • @sgaist

    I'm sorry for posting it again. The idea is the same but I'm looking for a more general procedure to make a custom widget.

    I followed @mrjj comments created a button as shown below:

    This widget contains four push buttons (for fine increment/decrement and double increment/decrement) and a label to show the current value. It is a standard form class. I need to make it as a standard widget.

    I'm still in question how to reuse it on my other forms?

  • @viniltc

    Basically there are two ways:

    In both cases you can use your widget in different projects (if you promote it, you have to include the source code / your widgets class)

Log in to reply