From b657496a0ba326af0688e9935069139c002849cf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 16 Feb 2016 12:41:11 +0100 Subject: QLineEdit: Use High DPI pixmap for clear button. Add a 32x32-pixmap to the style and factor out a function from QStyle::standardIcon() to assemble the icon. The 32x32 pixmap may also be used for the 16x16 case with devicePixelRatio=2. Change QLineEditIconButton to use QStyle::standardIcon() instead of QStyle::standardPixmap passing the QWindow to obtain the correct pixmap from the icon. Task-number: QTBUG-49374 Change-Id: I9895230f66911752cc13b7212609141610df0977 Reviewed-by: Giuseppe D'Angelo --- src/widgets/widgets/qlineedit_p.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/widgets/widgets/qlineedit_p.cpp') diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index ff4d0fec47..ff80c45c9a 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -317,14 +317,17 @@ QLineEditIconButton::QLineEditIconButton(QWidget *parent) void QLineEditIconButton::paintEvent(QPaintEvent *) { QPainter painter(this); + QWindow *window = Q_NULLPTR; + if (const QWidget *nativeParent = nativeParentWidget()) + window = nativeParent->windowHandle(); // Note isDown should really use the active state but in most styles // this has no proper feedback QIcon::Mode state = QIcon::Disabled; if (isEnabled()) state = isDown() ? QIcon::Selected : QIcon::Normal; - const QPixmap iconPixmap = icon().pixmap(QSize(IconButtonSize, IconButtonSize), - state, QIcon::Off); - QRect pixmapRect = QRect(QPoint(0, 0), iconPixmap.size() / iconPixmap.devicePixelRatio()); + const QSize iconSize(IconButtonSize, IconButtonSize); + const QPixmap iconPixmap = icon().pixmap(window, iconSize, state, QIcon::Off); + QRect pixmapRect = QRect(QPoint(0, 0), iconSize); pixmapRect.moveCenter(rect().center()); painter.setOpacity(m_opacity); painter.drawPixmap(pixmapRect, iconPixmap); @@ -416,7 +419,7 @@ QIcon QLineEditPrivate::clearButtonIcon() const Q_Q(const QLineEdit); QStyleOptionFrame styleOption; q->initStyleOption(&styleOption); - return QIcon(q->style()->standardPixmap(QStyle::SP_LineEditClearButton, &styleOption, q)); + return q->style()->standardIcon(QStyle::SP_LineEditClearButton, &styleOption, q); } void QLineEditPrivate::setClearButtonEnabled(bool enabled) -- cgit v1.2.3