PDA

View Full Version : Qt4 -> Qt5: QPainter scale



gavinmagnus
7th November 2016, 16:12
Hello,
I'm performing some conversion from Qt4 to Qt5. My colleague states, that the code below used to create a rectangle with 1 pixel border, covering nearly whole widget, on Qt 4.8.1




QPainter painter( this );
painter.scale( width(), height() );

painter.setPen( Qt::green );
painter.setBrush( Qt::yellow );
painter.drawRect( QRectF( 0.1, 0.1, 0.8, 0.8 ) );


However, when I run this on Qt 5.3.2, the scale works differently. I receive insanely oversized rectangle with really thick border. In other words it is zooming instead of changing distances between points on axes.

I couldn't find this information in any Qt4->Qt5 migration guide, can someone confirm or deny that anything was changed with scaling method?


EDIT:

Looks like this might be the thing:


// Qt4:
void QPainter::scale(qreal sx, qreal sy)
{
QMatrix m;
m.scale(sx, sy);
setMatrix(m, true); // however this calls setWorldMatrix( m ) anyway
}

// Qt5:
void QPainter::scale(qreal sx, qreal sy)
{
Q_D(QPainter);
if (!d->engine) {
qWarning("QPainter::scale: Painter not active");
return;
}

d->state->worldMatrix.scale(sx,sy);
d->state->WxF = true;
d->updateMatrix();
}

Is there an easy way to migrate my code?

anda_skoa
8th November 2016, 17:31
Have you tried explicitly setting the pen to be cosmetic?

Cheers,
_

gavinmagnus
9th November 2016, 10:30
Thank you, it works as intended.
Also sorry for the mess with second thread.