QTableView not displaying Icon for column zero
-
In my data() mf I have:
if (role == Qt::DecorationRole) { if (0 == index.column()) return rowIcon(file); else return QVariant(); }
rowIcon() looks like:
// // Work out which Icon to display based on the frame type // QVariant ImageListModel::rowIcon(const ListBitMap& file) const { QVariant result; PICTURETYPE type{ file.m_PictureType }; int16_t index{ 0 }; switch (type) { case PICTURETYPE_LIGHTFRAME: case PICTURETYPE_REFLIGHTFRAME: index = 0; break; case PICTURETYPE_DARKFRAME: case PICTURETYPE_DARKFLATFRAME: index = 1; break; case PICTURETYPE_FLATFRAME: index = 2; break; case PICTURETYPE_OFFSETFRAME: index = 3; break; default: return QVariant(); // we're outta here } // if (file.m_lNrChannels == 3) // index +=0; // Use xxxxColour Icons if (IsCYMGType(file.GetCFAType())) index += 4; // Use xxxxCMYG Icons else if (file.GetCFAType() != CFATYPE_NONE) index += 8; // Use xxxxRGB Icons else index += 12; // Use xxxxGreyscale Icons return ImageListModel::icons[index]; }
static inline const std::vector<QIcon> icons{ QIcon("qrc:///stacking/LightColour.png"), QIcon("qrc:///stacking/DarkColour.png"), QIcon("qrc:///stacking/FlatColour.png"), QIcon("qrc:///stacking/BiasColour.png"), QIcon("qrc:///stacking/LightCMYG.png"), QIcon("qrc:///stacking/DarkCMYG.png"), QIcon("qrc:///stacking/FlatCMYG.png"), QIcon("qrc:///stacking/BiasCMYG.png"), QIcon("qrc:///stacking/LightRGB.png"), QIcon("qrc:///stacking/DarkRGB.png"), QIcon("qrc:///stacking/FlatRGB.png"), QIcon("qrc:///stacking/BiasRGB.png"), QIcon("qrc:///stacking/LightGreyscale.png"), QIcon("qrc:///stacking/DarkGreyscale.png"), QIcon("qrc:///stacking/FlatGreyscale.png"), QIcon("qrc:///stacking/BiasGreyscale.png") };
which all seems to make sense to me - expect that I see no Icon displayed for column zero, even though I chased through rowIcon() in the debugger and could see a valid index being calculated, and the icons vector looks fine in the debugger too.
-
@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.