diff options
author | Morten Johan Sørvig <morten.sorvig@digia.com> | 2013-03-01 12:28:03 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-26 21:44:15 +0100 |
commit | d616915b0ab346c7e3e6944605e5822afd743f73 (patch) | |
tree | ad41ece64eb27a525d9d09efcaf102fc63ee419a /src/widgets | |
parent | 491dcbfac8da80bc573ba90959a3d610a55db4d0 (diff) |
Support high-dpi images.
When Qt::AA_UseHighDPIImages is set images and pixmaps
may be of the high-dpi type.
Account for this when calculating layout sizes by
clamping the size or dividing by devicePixelRatio()
to go from device pixels to device-independent pixels.
Change-Id: I7b7f4c36ebd83d72ecdf6fbe0ae20e20ed6540bb
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/itemviews/qstyleditemdelegate.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index e92ccc2455..b121800c31 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -355,7 +355,10 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, else mode = QIcon::Normal; QIcon::State state = option->state & QStyle::State_Open ? QIcon::On : QIcon::Off; - option->decorationSize = option->icon.actualSize(option->decorationSize, mode, state); + QSize actualSize = option->icon.actualSize(option->decorationSize, mode, state); + // For highdpi icons actualSize might be larger than decorationSize, which we don't want. Clamp it to decorationSize. + option->decorationSize = QSize(qMin(option->decorationSize.width(), actualSize.width()), + qMin(option->decorationSize.height(), actualSize.height())); break; } case QVariant::Color: { @@ -367,13 +370,13 @@ void QStyledItemDelegate::initStyleOption(QStyleOptionViewItem *option, case QVariant::Image: { QImage image = qvariant_cast<QImage>(value); option->icon = QIcon(QPixmap::fromImage(image)); - option->decorationSize = image.size(); + option->decorationSize = image.size() / image.devicePixelRatio(); break; } case QVariant::Pixmap: { QPixmap pixmap = qvariant_cast<QPixmap>(value); option->icon = QIcon(pixmap); - option->decorationSize = pixmap.size(); + option->decorationSize = pixmap.size() / pixmap.devicePixelRatio(); break; } default: |