QTableView not displaying Icon for column zero
-
Hi,
In addition to @mpergand checks, shouldn't your path start with ":/" since it's a file path and not a URL ?
@SGaist said in QTableView not displaying Icon for column zero:
Hi,
In addition to @mpergand checks, shouldn't your path start with ":/" since it's a file path and not a URL ?
I don't know: The docs I am looking at say:
By default, resources are accessible in the application under the same file name as they have in the source tree, with a :/ prefix, or by a URL with a qrc scheme.
For example, the file path :/images/cut.png or the URL qrc:///images/cut.png would give access to the cut.png file, whose location in the application's source tree is images/cut.png. This can be changed using the file tag's alias attribute:
<file alias="cut-img.png">images/cut.png</file>so I used the qrc::/// format - I will try the :/ format
-
QIcon takes a file path, not a QUrl.
-
Gotcha
I changed the code to use :/ instead of qrc:/// and added code to the end of rowIcon() so the end of it now reads:
if (ImageListModel::icons[index].isNull()) { qDebug("null icon"); } return ImageListModel::icons[index]; }and the qDebug line isn't triggered, so I guess the code is returning a valid QIcon.
Sadly no Icon is displayed :(
-
What if you test with the full path to the file system ?
-
@SGaist Aha! That was much more interesting:

So it looks like I can't use that form of static initialisation for the array of Icons. I'm somewhat surprised I didn't get that error when using the ":/" format!
I'll see what other solution I can come up with to initialise that array.
Thank you
-
I added this to the ctor:
// // Populate the Icon array if it's not already been done // if (0 == ImageListModel::icons.size()) { std::lock_guard lock(ImageListModel::mutex); if (0 == ImageListModel::icons.size()) // check for race condtion { ImageListModel::icons.emplace_back(":/stacking/LightColour.png"); // etc } }That worked just fine - thank you again for the push to try with filepaths which exposed the real issue.