Qt UI: Correctly load icon from absolute path [SLE-15-SP4] #94
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Target Release
This is for SLE-15 SP4. See below for the merge PRs to SLE-15-SP5 and to master / Factory / TW.
Bugzilla
https://bugzilla.suse.com/show_bug.cgi?id=1210591
Problem
Loading icons from a fixed path didn't work: There was never an icon on the screen.
It worked with icons from the desktop theme and with compiled-in icons, but not with anything else; in particular not with icons from a full path.
Cause
The fallback cascade that tried to load icons relied on checking
QIcon::isNull()
, assuming that a failed attempt to load an icon would result in that function returningtrue
as one would expect.libyui/libyui-qt/src/YQUI.cc
Lines 694 to 720 in 9cc9049
But that assumption is wrong. In reality, that
QIcon::isNull()
has a really bizarre interpretation what it means for a QIcon to be null:https://doc.qt.io/qt-5/qicon.html#isNull
Fix
Don't rely on that
QIcon::isNull()
function; it almost never returns a useful result.After some experimentation, it turned out that
QIcon::availableSizes()
which returns a list of sizes for that icon that the loaded file(s) can generate is an empty list (size 0) if the icon could not be loaded, and non-empty (size > 0) if it was successful.Added a function with a speaking name for that check so it becomes clear what's going on.
Test
Manual test with the Table-icons.rb UI example (after adapting the path to use one that actually exists and has icons) from yast2-ycp-bindings:
https://github.com/yast/yast-ycp-ui-bindings/blob/master/examples/Table-icons.rb
Related PRs