In case of drawcontrol function of QStyle class how can we draw control with pixmap?
Suppose i want to draw a custom checkbox where i want to draw image in case of default check box without affecting the checkbox text so how can we use drawcontrol class of Qstyle for that? or is their any other function for drawing it.
12 replies
QPainter is used for drawing on widgets (and other painting surfaces). Did you check its documentation? Did you notice the methods for rendering text and for rendering QPixmaps and QImages?
QPainter is used for drawing on widgets (and other painting surfaces). Did you check its documentation? Did you notice the methods for rendering text and for rendering QPixmaps and QImages?
but if i will use QPainter for drawing like
- drawpixmap()
No, of course not. What is painted is just that: painted. The interactivity comes from the widget itself.
I was trying the following code in paintevent for checkbox
when i am using the function
- this->settext("dfdf")
Of course, because you are not drawing the text. If you reimplement the paintEvent function, then that is the paintEvent function that will be called, not the original one that also takes care of drawing the text. From the top of my head, QStyle does offer methods to render this text already, but otherwise it is just a matter of rendering it yourself using the same painter. Alternatively, you could try to just call the base class implementation of the render method, and only then draw your pixmap on top of that.
Of course, because you are not drawing the text. If you reimplement the paintEvent function, then that is the paintEvent function that will be called, not the original one that also takes care of drawing the text. From the top of my head, QStyle does offer methods to render this text already, but otherwise it is just a matter of rendering it yourself using the same painter. Alternatively, you could try to just call the base class implementation of the render method, and only then draw your pixmap on top of that.
Sorry but this i didn’t understand “Alternatively, you could try to just call the base class implementation of the render method, and only then draw your pixmap on top of that” can you please explain it?
You subclassed a another class (a QStyle derived class, I gather), and you have reimplemented one of its methods. Right?
In general, if you want the base class (the class you subclassed or derived from) method to actually do whatever it was doing before you dediced to subclass and reimplement that method, you need to call it’s implementation from your own implementation.
There is a special syntax to do that:
- class Derived: public Base {
- virtual void doStuff() {
- Base::doStuff(); // <-- call to base class implementation first
- //do whatever else you want to do
- }
- }
You must log in to post a reply. Not a member yet? Register here!



