Flip part of drawing in a QPaintDevice
Hi All,
I'd like to paint part of a drawing flipped horizontally on a QPaintDevice.
Here is the problem:
I have a QWidget on which I want to draw a checkbox flipped horizontally at some position inside the widget.
The porblem is that the checkbox is smaller than the size of the QWidget, so painter.translate(-1.0,0) won't work because the checkbox will appear at the opposite side of the widget.
The solution I found actually is to draw the checkbox flipped inside a pixmap of the size of the checkbox (in that case transtale() will do the job) and then draw the pixmap on the widget.
Is there a faster way to this (flip only part the painting inside the widget) without intermediate structures ?
Thanks
Re: Flip part of drawing in a QPaintDevice
translate moves the origin on the drawing, flipping would be scaling with -1 on the axis you want to flip.
Potentially translated to the origin of the flip first, of course.
Cheers,
_
Re: Flip part of drawing in a QPaintDevice
Ok in fact scale(-1,0) has nothing to do with the paint device width. It just multiplies X coordinates passed to qpainter by -1.
so to re-align my checkbox inside the original rect, I must do:
bounds.getRect(&x,&y,&w,&h); // this is where I must draw
painter->scale(-1.0,1.0); // x becomes -x
painter->translate(-2*x-w,0); // then bring it back to original position. transformations are cumulative
Thanks
Re: Flip part of drawing in a QPaintDevice
Quote:
Originally Posted by
dextermagnific
Ok in fact scale(-1,0) has nothing to do with the paint device width. It just multiplies X coordinates passed to qpainter by -1.
Of course, why would that change the width of the device?
The transformations are applied to drawing operations, not to devices properties.
Cheers,
_