Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Making custom button widget
Forum Update on Monday, May 27th 2025

Making custom button widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by
    #1

    Hi All,

    I need a custom button widget as shown below:

    0_1565276664225_Capture.JPG

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

    Thank you

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      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
          {
              Q_OBJECT
          public:
              Vcr( QWidget *parent = 0, const char *name = 0 );
              ~Vcr() {}
          signals:
              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.

      1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #3

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        V 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

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

          V Offline
          V Offline
          viniltc
          wrote on last edited by viniltc
          #4

          @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:
          0_1565338655673_Capture.JPG

          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?

          Pl45m4P 1 Reply Last reply
          0
          • V viniltc

            @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:
            0_1565338655673_Capture.JPG

            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?

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @viniltc

            Basically there are two ways:

            • Promote
            • Build Widget

            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)


            If debugging is the process of removing software bugs, then programming must be the process of putting them in.

            ~E. W. Dijkstra

            1 Reply Last reply
            3

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved