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
Forum Updated to NodeBB v4.3 + New Features

QTableView not displaying Icon for column zero

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 856 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.
  • 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