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
painter.scale( width(), height() );
painter.setPen( Qt::green );
painter.setBrush( Qt::yellow );
painter.
drawRect( QRectF( 0.1,
0.1,
0.8,
0.8 ) );
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 ) );
To copy to clipboard, switch view to plain text mode
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
) {
m.scale(sx, sy);
setMatrix(m, true); // however this calls setWorldMatrix( m ) anyway
}
// Qt5:
void QPainter::scale(qreal sx, qreal sy
) {
if (!d->engine) {
qWarning("QPainter::scale: Painter not active");
return;
}
d->state->worldMatrix.scale(sx,sy);
d->state->WxF = true;
d->updateMatrix();
}
// 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();
}
To copy to clipboard, switch view to plain text mode
Is there an easy way to migrate my code?
Bookmarks