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>
This commit is contained in:
parent
491dcbfac8
commit
d616915b0a
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user