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 <giuseppe.dangelo@kdab.com>
This commit is contained in:
parent
a125b2c4c7
commit
b657496a0b
BIN
src/widgets/styles/images/cleartext-32.png
Normal file
BIN
src/widgets/styles/images/cleartext-32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 410 B |
@ -5198,6 +5198,30 @@ static QPixmap cachedPixmapFromXPM(const char * const *xpm)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QIcon clearTextIcon(bool rtl)
|
||||||
|
{
|
||||||
|
const QString directionalThemeName = rtl
|
||||||
|
? QStringLiteral("edit-clear-locationbar-ltr") : QStringLiteral("edit-clear-locationbar-rtl");
|
||||||
|
if (QIcon::hasThemeIcon(directionalThemeName))
|
||||||
|
return QIcon::fromTheme(directionalThemeName);
|
||||||
|
const QString themeName = QStringLiteral("edit-clear");
|
||||||
|
if (QIcon::hasThemeIcon(themeName))
|
||||||
|
return QIcon::fromTheme(themeName);
|
||||||
|
|
||||||
|
QIcon icon;
|
||||||
|
#ifndef QT_NO_IMAGEFORMAT_PNG
|
||||||
|
QPixmap clearText16(QStringLiteral(":/qt-project.org/styles/commonstyle/images/cleartext-16.png"));
|
||||||
|
Q_ASSERT(!clearText16.size().isEmpty());
|
||||||
|
icon.addPixmap(clearText16);
|
||||||
|
QPixmap clearText32(QStringLiteral(":/qt-project.org/styles/commonstyle/images/cleartext-32.png"));
|
||||||
|
Q_ASSERT(!clearText32.size().isEmpty());
|
||||||
|
icon.addPixmap(clearText32);
|
||||||
|
clearText32.setDevicePixelRatio(2); // The 32x32 pixmap can also be used for 16x16/devicePixelRatio=2
|
||||||
|
icon.addPixmap(clearText32);
|
||||||
|
#endif // !QT_NO_IMAGEFORMAT_PNG
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
/*! \reimp */
|
/*! \reimp */
|
||||||
QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
|
QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
|
||||||
const QWidget *widget) const
|
const QWidget *widget) const
|
||||||
@ -5370,12 +5394,8 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SP_LineEditClearButton: {
|
case SP_LineEditClearButton:
|
||||||
QString themeName = rtl ? QStringLiteral("edit-clear-locationbar-ltr") : QStringLiteral("edit-clear-locationbar-rtl");
|
pixmap = clearTextIcon(rtl).pixmap(16);
|
||||||
if (!QIcon::hasThemeIcon(themeName))
|
|
||||||
themeName = QStringLiteral("edit-clear");
|
|
||||||
pixmap = QIcon::fromTheme(themeName).pixmap(16);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -5505,8 +5525,6 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti
|
|||||||
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-16.png"));
|
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-16.png"));
|
||||||
case SP_MediaVolumeMuted:
|
case SP_MediaVolumeMuted:
|
||||||
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png"));
|
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/media-volume-muted-16.png"));
|
||||||
case SP_LineEditClearButton:
|
|
||||||
return QPixmap(QStringLiteral(":/qt-project.org/styles/commonstyle/images/cleartext-16.png"));
|
|
||||||
#endif // QT_NO_IMAGEFORMAT_PNG
|
#endif // QT_NO_IMAGEFORMAT_PNG
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -5556,6 +5574,8 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
|
|||||||
const QWidget *widget) const
|
const QWidget *widget) const
|
||||||
{
|
{
|
||||||
QIcon icon;
|
QIcon icon;
|
||||||
|
const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft());
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
switch (standardIcon) {
|
switch (standardIcon) {
|
||||||
case SP_DriveCDIcon:
|
case SP_DriveCDIcon:
|
||||||
@ -5597,6 +5617,9 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
|
|||||||
icon.addPixmap(pixmap);
|
icon.addPixmap(pixmap);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SP_LineEditClearButton:
|
||||||
|
icon = clearTextIcon(rtl);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -5605,7 +5628,6 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft());
|
|
||||||
if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) {
|
if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) {
|
||||||
switch (standardIcon) {
|
switch (standardIcon) {
|
||||||
case SP_DirHomeIcon:
|
case SP_DirHomeIcon:
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/qt-project.org/styles/commonstyle">
|
<qresource prefix="/qt-project.org/styles/commonstyle">
|
||||||
<file>images/cleartext-16.png</file>
|
<file>images/cleartext-16.png</file>
|
||||||
|
<file>images/cleartext-32.png</file>
|
||||||
<file>images/filelink-16.png</file>
|
<file>images/filelink-16.png</file>
|
||||||
<file>images/filelink-32.png</file>
|
<file>images/filelink-32.png</file>
|
||||||
<file>images/filelink-128.png</file>
|
<file>images/filelink-128.png</file>
|
||||||
|
@ -317,14 +317,17 @@ QLineEditIconButton::QLineEditIconButton(QWidget *parent)
|
|||||||
void QLineEditIconButton::paintEvent(QPaintEvent *)
|
void QLineEditIconButton::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
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
|
// Note isDown should really use the active state but in most styles
|
||||||
// this has no proper feedback
|
// this has no proper feedback
|
||||||
QIcon::Mode state = QIcon::Disabled;
|
QIcon::Mode state = QIcon::Disabled;
|
||||||
if (isEnabled())
|
if (isEnabled())
|
||||||
state = isDown() ? QIcon::Selected : QIcon::Normal;
|
state = isDown() ? QIcon::Selected : QIcon::Normal;
|
||||||
const QPixmap iconPixmap = icon().pixmap(QSize(IconButtonSize, IconButtonSize),
|
const QSize iconSize(IconButtonSize, IconButtonSize);
|
||||||
state, QIcon::Off);
|
const QPixmap iconPixmap = icon().pixmap(window, iconSize, state, QIcon::Off);
|
||||||
QRect pixmapRect = QRect(QPoint(0, 0), iconPixmap.size() / iconPixmap.devicePixelRatio());
|
QRect pixmapRect = QRect(QPoint(0, 0), iconSize);
|
||||||
pixmapRect.moveCenter(rect().center());
|
pixmapRect.moveCenter(rect().center());
|
||||||
painter.setOpacity(m_opacity);
|
painter.setOpacity(m_opacity);
|
||||||
painter.drawPixmap(pixmapRect, iconPixmap);
|
painter.drawPixmap(pixmapRect, iconPixmap);
|
||||||
@ -416,7 +419,7 @@ QIcon QLineEditPrivate::clearButtonIcon() const
|
|||||||
Q_Q(const QLineEdit);
|
Q_Q(const QLineEdit);
|
||||||
QStyleOptionFrame styleOption;
|
QStyleOptionFrame styleOption;
|
||||||
q->initStyleOption(&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)
|
void QLineEditPrivate::setClearButtonEnabled(bool enabled)
|
||||||
|
Loading…
Reference in New Issue
Block a user