Good day!
Maybe I'm wrong, but in my opinion the problem is solved in this way:
1) Inherit from QAbstractButton or QCheckBox . What exactly you need to think about, since QCheckBox three states ("selected", "not selected", "partially allocated", see enum Qt::CheckState ) and it will have to be processed somehow. I would nevertheless inherit from QAbstractButton .
2) Redefine paitEvent(QPaintEvent*) anyway. Make your own drawing and preferably using QPalette.
3) I would suggest doing an animation like this:
a) Create a private class inherited from QObject (for QPropertyAnimation). The idiom of the Pointer To Implemetation (macros Q_DECLARE_PRIVATE and Q_D ) is very good for this. You will need to create a separate header file with the _p suffix (for example mybutton_p.h ) for the MOC to work properly. This approach is often used in the Qt library itself. More detail here and here .
b) We declare and implement in a private class all the necessary properties (slider position, text, etc.) while taking into account that when changing some properties, the widget itself needs to be redrawn.
c) Create a slot in a private class, for example, void animate(bool) . The parameter of this slot will be an indicator in which direction to play the animation.
d) Implement a slot using QPropertyAnimation. Here you can use the enum Direction for the correct playback direction and use qreal to interpolate the current slider position (for example, 0.0 is the leftmost ("off" state), 1.0 is the rightmost ("on" state)).
e) Connect the void animate(bool) slot of our private class with the clicked(bool) signal of the main class. This can be done in the constructor of the main class.
In conclusion, you can offer to search for all sorts of resources - maybe someone has already tried to implement something like that. In any case, it may push on some thoughts or ideas.
Successes!
UPD: implemented for the sake of interest - everything took about an hour of work. Here's what happened:
In off state: 
In the on state: 
Link to the project at SourceForge: https://sourceforge.net/projects/qslideswitcher/
Link to the study: https://ru.stackoverflow.com/research/289306/widgets-%D1%80%D0%B5%D0%B0%D0%BB%D0%B8%D0%B7 % 86% D0% B8% D1% 8F-qt-off-on-button-% D1% 81% D0% BE-% D1% 81% D0% BB% D0% B0% D0% B9% D0% B4% D0 % B5% D1% 80% D0% BE% D0% BC-% D0% B1% D0% B5% D0% B7-qml