diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-23 16:04:49 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-02-16 14:20:50 +0100 |
commit | 277d77029d7fe8f46c6ee101869dcff389426cb1 (patch) | |
tree | 21d5b70cd39ffa1d085cb686924c85dd8d665e8d /src/plugins/platformthemes | |
parent | 8fc37349e32629c8cf84eae97e2e9d80b194de21 (diff) |
QGtk3Theme: Fix QGtk3Interface::fileIcon
By failing to set the G_FILE_ATTRIBUTE_STANDARD_ICON attribute, the
"icon" returned by g_file_info_get_icon was always null and a
GLib-GIO-CRITICAL warning was output to the console (at least since glib
2.76.0)[1].
After adding the necessary attribute, the code was crashing, because now
a valid icon was returned, however the icon should not be freed[2],
which is why I removed the "g_object_unref(icon)".
Now it was no longer crashing, but the size of the icons was off. It was
passing GTK_ICON_SIZE_BUTTON (4) to gtk_icon_theme_lookup_by_gicon where
a size in pixels was expected. I chose 16 because that's the pixel size
associated with GTK_ICON_SIZE_BUTTON[3].
Finally I noticed the returned icons had the wrong color. It seems that
a GdkPixbuf uses RGBA8888 format[4]. Adding an explicit conversion to
ARGB32 made the icons look correct for me.
[1] https://gitlab.gnome.org/GNOME/glib/-/commit/ed8e86a7d41a0900d8fa57edc64264d04cf8135b
[2] https://docs.gtk.org/gio/method.FileInfo.get_icon.html
[3] https://docs.gtk.org/gtk3/enum.IconSize.html#button
[4] https://docs.gtk.org/gdk-pixbuf/class.Pixbuf.html#image-data
[ChangeLog][Platform Specific Changes][Linux] Fixed file icons provided by QFileIconProvider when using the gtk3 platform theme.
Pick-to: 6.5 6.6 6.7
Change-Id: I312ef76ac28bc28435b756d299998485db122906
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/plugins/platformthemes')
-rw-r--r-- | src/plugins/platformthemes/gtk3/qgtk3interface.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/plugins/platformthemes/gtk3/qgtk3interface.cpp b/src/plugins/platformthemes/gtk3/qgtk3interface.cpp index 33d0182521..a35e211fbf 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3interface.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3interface.cpp @@ -296,8 +296,10 @@ QImage QGtk3Interface::qt_convert_gdk_pixbuf(GdkPixbuf *buf) const const int width = gdk_pixbuf_get_width(buf); const int height = gdk_pixbuf_get_height(buf); const int bpl = gdk_pixbuf_get_rowstride(buf); - QImage converted(data, width, height, bpl, QImage::Format_ARGB32); - return converted.copy(); // detatch to survive lifetime of buf + QImage converted(data, width, height, bpl, QImage::Format_RGBA8888); + + // convert to more optimal format and detach to survive lifetime of buf + return converted.convertToFormat(QImage::Format_ARGB32_Premultiplied); } /*! @@ -666,7 +668,7 @@ QIcon QGtk3Interface::fileIcon(const QFileInfo &fileInfo) const if (!file) return QIcon(); - GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, + GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, nullptr, nullptr); if (!info) { g_object_unref(file); @@ -681,12 +683,11 @@ QIcon QGtk3Interface::fileIcon(const QFileInfo &fileInfo) const } GtkIconTheme *theme = gtk_icon_theme_get_default(); - GtkIconInfo *iconInfo = gtk_icon_theme_lookup_by_gicon(theme, icon, GTK_ICON_SIZE_BUTTON, + GtkIconInfo *iconInfo = gtk_icon_theme_lookup_by_gicon(theme, icon, 16, GTK_ICON_LOOKUP_FORCE_SIZE); if (!iconInfo) { g_object_unref(file); g_object_unref(info); - g_object_unref(icon); return QIcon(); } @@ -694,7 +695,6 @@ QIcon QGtk3Interface::fileIcon(const QFileInfo &fileInfo) const QImage image = qt_convert_gdk_pixbuf(buf); g_object_unref(file); g_object_unref(info); - g_object_unref(icon); g_object_unref(buf); return QIcon(QPixmap::fromImage(image)); } |