Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableView not displaying Icon for column zero
Qt 6.11 is out! See what's new in the release blog

QTableView not displaying Icon for column zero

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 1.0k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • PerdrixP Offline
    PerdrixP Offline
    Perdrix
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • PerdrixP Perdrix

      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.

      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @Perdrix
      Check QIcon::isNull()

      PerdrixP 1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        In addition to @mpergand checks, shouldn't your path start with ":/" since it's a file path and not a URL ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        PerdrixP 1 Reply Last reply
        1
        • M mpergand

          @Perdrix
          Check QIcon::isNull()

          PerdrixP Offline
          PerdrixP Offline
          Perdrix
          wrote on last edited by
          #4

          @mpergand said in QTableView not displaying Icon for column zero:

          @Perdrix
          Check QIcon::isNull()

          Roger- wilco

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            In addition to @mpergand checks, shouldn't your path start with ":/" since it's a file path and not a URL ?

            PerdrixP Offline
            PerdrixP Offline
            Perdrix
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              QIcon takes a file path, not a QUrl.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • PerdrixP Offline
                PerdrixP Offline
                Perdrix
                wrote on last edited by
                #7

                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 :(

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  What if you test with the full path to the file system ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  PerdrixP 1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    ChrisW67
                    wrote on last edited by ChrisW67
                    #9

                    Also check that your code is not exiting via the return in the switch default.

                    PerdrixP 1 Reply Last reply
                    0
                    • C ChrisW67

                      Also check that your code is not exiting via the return in the switch default.

                      PerdrixP Offline
                      PerdrixP Offline
                      Perdrix
                      wrote on last edited by
                      #10

                      @ChrisW67 said in QTableView not displaying Icon for column zero:

                      Also check that your code is not exiting via the return in the switch default.

                      Yes, I checked that under the debugger - never hit that path.

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        What if you test with the full path to the file system ?

                        PerdrixP Offline
                        PerdrixP Offline
                        Perdrix
                        wrote on last edited by
                        #11

                        @SGaist Aha! That was much more interesting:

                        d831b95d-f9af-4c30-b4c1-0452388bad34-image.png

                        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

                        1 Reply Last reply
                        0
                        • PerdrixP Offline
                          PerdrixP Offline
                          Perdrix
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          1

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved