PDA

View Full Version : mirror filping ???



jesse_mark
31st October 2012, 20:27
hell guys,

If i draw a rect using painter ... how can mirror it using the the origin point. ????

thanks

ChrisW67
1st November 2012, 04:15
QPainter::scale() with a negative scale factor works (if I understood your question):


class Widget: public QWidget
{
Q_OBJECT
public:
Widget(QWidget *p = 0): QWidget(p) {
resize(640, 480);
}

void paintEvent(QPaintEvent *event) {
QRect r(50, 50, 200, 100);

// for a bit of colour
QLinearGradient linearGradient(r.topRight(), r.bottomLeft());
linearGradient.setColorAt(0.0, Qt::white);
linearGradient.setColorAt(0.2, Qt::green);
linearGradient.setColorAt(1.0, Qt::black);

QPainter p(this);
p.translate(320, 0); // put x origin in centre

p.setBrush(linearGradient);
p.drawRect(r);

p.setPen(Qt::red);
p.scale(-1.0, 1.0);
p.drawRect(r);

}
};

jesse_mark
1st November 2012, 15:25
Great this exactly what i mean.

but now i faced other problem ... I have text along the rect sides (bottom and left) when i flip the text show flipped as well, is there a way where i can make the Text show correctly but still in the direction of the painter ?

Thank you so much

Added after 44 minutes:

I tried to use

p->setLayoutDirection(Qt::RightToLeft);

but it didn't work, it didn't show any affect actually.

ChrisW67
1st November 2012, 20:33
You need to calculate where the text should go and then QPainter::translate() QPainter::drawText() it yourself.