In case of drawcontrol function of QStyle class how can we draw control with pixmap?
-
[quote author="Andre" date="1325572914"][[doc: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?[/quote]
but if i will use QPainter for drawing like @drawpixmap()@ on widget.Does I have to take care of all the default functionalities of the widget? -
[quote author="Andre" date="1325573677"]No, of course not. What is painted is just that: painted. The interactivity comes from the widget itself. [/quote]
I was trying the following code in paintevent for checkbox
@QPainter painter(this);QPixmap pixmap(":/ab_close.png"); painter.drawPixmap (QRect(0,0,13,15),pixmap, QRect(0,0,13,15));
@
when i am using the function @this->settext("dfdf")@ in constructor of checkbox class the text is not displaying only the image which i have set is coming. -
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.
-
[quote author="Andre" date="1325576703"]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. [/quote]
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
}
}
@ -
[quote author="Andre" date="1325659958"]Could you post your whole implementation of your paintEvent()?[/quote]
this is my implementation of paintevent
@
void checkbox::paintEvent (QPaintEvent *e)
{
QCheckBox::paintEvent (e);
QPainter paint(this);
paint.drawPixmap (QRect(0,0,10,10), pixmap, QRect(0,0,10,10));}
@
Here i am getting both the image and the default widget as output.