summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-02-16 12:41:11 +0100
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2016-03-22 09:25:00 +0000
commitb657496a0ba326af0688e9935069139c002849cf (patch)
tree68cd9298778771e43955125720dddaf395a783d5 /src/widgets/styles
parenta125b2c4c744b8f5b9136170db66840eeaf1f278 (diff)
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>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/images/cleartext-32.pngbin0 -> 410 bytes
-rw-r--r--src/widgets/styles/qcommonstyle.cpp40
-rw-r--r--src/widgets/styles/qstyle.qrc1
3 files changed, 32 insertions, 9 deletions
diff --git a/src/widgets/styles/images/cleartext-32.png b/src/widgets/styles/images/cleartext-32.png
new file mode 100644
index 0000000000..ff5a2b5ec1
--- /dev/null
+++ b/src/widgets/styles/images/cleartext-32.png
Binary files differ
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index 355a3d2c3f..748cef20c1 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -5198,6 +5198,30 @@ static QPixmap cachedPixmapFromXPM(const char * const *xpm)
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 */
QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *option,
const QWidget *widget) const
@@ -5370,12 +5394,8 @@ QPixmap QCommonStyle::standardPixmap(StandardPixmap sp, const QStyleOption *opti
}
}
break;
- case SP_LineEditClearButton: {
- QString themeName = rtl ? QStringLiteral("edit-clear-locationbar-ltr") : QStringLiteral("edit-clear-locationbar-rtl");
- if (!QIcon::hasThemeIcon(themeName))
- themeName = QStringLiteral("edit-clear");
- pixmap = QIcon::fromTheme(themeName).pixmap(16);
- }
+ case SP_LineEditClearButton:
+ pixmap = clearTextIcon(rtl).pixmap(16);
break;
default:
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"));
case SP_MediaVolumeMuted:
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
default:
break;
@@ -5556,6 +5574,8 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
const QWidget *widget) const
{
QIcon icon;
+ const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft());
+
#ifdef Q_OS_WIN
switch (standardIcon) {
case SP_DriveCDIcon:
@@ -5597,6 +5617,9 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
icon.addPixmap(pixmap);
}
break;
+ case SP_LineEditClearButton:
+ icon = clearTextIcon(rtl);
+ break;
default:
break;
}
@@ -5605,7 +5628,6 @@ QIcon QCommonStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption
#endif
- const bool rtl = (option && option->direction == Qt::RightToLeft) || (!option && QApplication::isRightToLeft());
if (QApplication::desktopSettingsAware() && !QIcon::themeName().isEmpty()) {
switch (standardIcon) {
case SP_DirHomeIcon:
diff --git a/src/widgets/styles/qstyle.qrc b/src/widgets/styles/qstyle.qrc
index c063ec5036..d8c73dd6fa 100644
--- a/src/widgets/styles/qstyle.qrc
+++ b/src/widgets/styles/qstyle.qrc
@@ -1,6 +1,7 @@
<RCC>
<qresource prefix="/qt-project.org/styles/commonstyle">
<file>images/cleartext-16.png</file>
+ <file>images/cleartext-32.png</file>
<file>images/filelink-16.png</file>
<file>images/filelink-32.png</file>
<file>images/filelink-128.png</file>