QLabel: take DPR of QMovie in account when calculating sizeHint

QLabel already does that for QPixmap, so just do the same for
QMovie's current pixmap.

Task-number: QTBUG-48157
Change-Id: I7b26460f778e56ff017a5efd433f8929f30e4b41
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
Daniel Vrátil 2016-11-07 09:40:34 +01:00
parent c83ba01f7b
commit 9de3b15d07
3 changed files with 25 additions and 0 deletions

View File

@ -579,6 +579,7 @@ QSize QLabelPrivate::sizeForWidth(int w) const
#ifndef QT_NO_MOVIE
} else if (movie && !movie->currentPixmap().isNull()) {
br = movie->currentPixmap().rect();
br.setSize(br.size() / movie->currentPixmap().devicePixelRatio());
#endif
} else if (isTextLabel) {
int align = QStyle::visualAlignment(textDirection(), QFlag(this->align));

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

View File

@ -101,6 +101,9 @@ private Q_SLOTS:
void taskQTBUG_7902_contextMenuCrash();
#endif
void taskQTBUG_48157_dprPixmap();
void taskQTBUG_48157_dprMovie();
private:
QLabel *testWidget;
QPointer<Widget> test_box;
@ -546,5 +549,26 @@ void tst_QLabel::taskQTBUG_7902_contextMenuCrash()
}
#endif
void tst_QLabel::taskQTBUG_48157_dprPixmap()
{
QLabel label;
QPixmap pixmap;
pixmap.load(QFINDTESTDATA(QStringLiteral("red@2x.png")));
QCOMPARE(pixmap.devicePixelRatio(), 2.0);
label.setPixmap(pixmap);
QCOMPARE(label.sizeHint(), pixmap.rect().size() / pixmap.devicePixelRatio());
}
void tst_QLabel::taskQTBUG_48157_dprMovie()
{
QLabel label;
QMovie movie;
movie.setFileName(QFINDTESTDATA(QStringLiteral("red@2x.png")));
movie.start();
QCOMPARE(movie.currentPixmap().devicePixelRatio(), 2.0);
label.setMovie(&movie);
QCOMPARE(label.sizeHint(), movie.currentPixmap().size() / movie.currentPixmap().devicePixelRatio());
}
QTEST_MAIN(tst_QLabel)
#include "tst_qlabel.moc"