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. I have a QTreeview with 2 columns. One column there is supposed to be a pixmap and the other column has pixmap and icon. The column with just the pixmap does not show anything.
Forum Updated to NodeBB v4.3 + New Features

I have a QTreeview with 2 columns. One column there is supposed to be a pixmap and the other column has pixmap and icon. The column with just the pixmap does not show anything.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 124 Views
  • 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.
  • T Offline
    T Offline
    Tater
    wrote on last edited by
    #1

    I have a pixmapList that holds my visibility icons. I am trying to add the visibility icon just for column = 1. Everything populates correctly for column=0

        this->VisiblePixmapList = new QPixmap[(int)(VisibleIconType::LAST) + 1];
        this->VisiblePixmapList[(int)VisibleIconType::EYEBALL].load(":/images/Eyeball.png");
        this->VisiblePixmapList[(int)VisibleIconType::EYEBALL_GRAY].load(":/images/EyeballClosed.png");
    
        QPixmap emptyPixmap(16,16);
        emptyPixmap.fill();
        this->VisiblePixmapList[(int)VisibleIconType::LAST] = emptyPixmap;
    
    QVariant function::data(const QModelIndex& idx, int role) const
    {
        if (!idx.isValid() || idx.model() != this)
        {
            return QVariant();
        }
        auto item = reinterpret_cast<functionItem*>(idx.internalPointer());
    
        auto source = item->Node;
        switch (role)
        {
        case Qt::ToolTipRole:
            if (source)
            {
                return QVariant(source->getToolTips().c_str());
            }
    
            // THE BELOW DOES NOT WORK LIKE I INTEND
        case Qt::DisplayRole:
            if (idx.column() == 1)
            {
                auto test = this->VisiblePixmapList[(int)item->VisibilityIcon];
                auto testSize = test.size();
                auto test2 = test.scaled(QSize(32,32));
                return QVariant(test2);
            }
    
        case Qt::EditRole:
            if (idx.column() == 0)
            {
                if (source)
                {
                    return QVariant(source->getName().c_str());
                }
                else
                {
                    qDebug() << "Cannot decide type.";
                }
            }
            break;
    
        case Qt::DecorationRole:
            if (idx.column() == 0 && this->PixmapList)
            {
                if (item && item->getType() != function::Invalid)
                {
                    auto scaledPixMap = this->PixmapList[(int)item->getIconType()].scaled(QSize(32,32));
                    return QVariant(scaledPixMap);
                }
            }
            break;
        }
        return QVariant();
    }
    
    JonBJ 1 Reply Last reply
    0
    • T Tater

      I have a pixmapList that holds my visibility icons. I am trying to add the visibility icon just for column = 1. Everything populates correctly for column=0

          this->VisiblePixmapList = new QPixmap[(int)(VisibleIconType::LAST) + 1];
          this->VisiblePixmapList[(int)VisibleIconType::EYEBALL].load(":/images/Eyeball.png");
          this->VisiblePixmapList[(int)VisibleIconType::EYEBALL_GRAY].load(":/images/EyeballClosed.png");
      
          QPixmap emptyPixmap(16,16);
          emptyPixmap.fill();
          this->VisiblePixmapList[(int)VisibleIconType::LAST] = emptyPixmap;
      
      QVariant function::data(const QModelIndex& idx, int role) const
      {
          if (!idx.isValid() || idx.model() != this)
          {
              return QVariant();
          }
          auto item = reinterpret_cast<functionItem*>(idx.internalPointer());
      
          auto source = item->Node;
          switch (role)
          {
          case Qt::ToolTipRole:
              if (source)
              {
                  return QVariant(source->getToolTips().c_str());
              }
      
              // THE BELOW DOES NOT WORK LIKE I INTEND
          case Qt::DisplayRole:
              if (idx.column() == 1)
              {
                  auto test = this->VisiblePixmapList[(int)item->VisibilityIcon];
                  auto testSize = test.size();
                  auto test2 = test.scaled(QSize(32,32));
                  return QVariant(test2);
              }
      
          case Qt::EditRole:
              if (idx.column() == 0)
              {
                  if (source)
                  {
                      return QVariant(source->getName().c_str());
                  }
                  else
                  {
                      qDebug() << "Cannot decide type.";
                  }
              }
              break;
      
          case Qt::DecorationRole:
              if (idx.column() == 0 && this->PixmapList)
              {
                  if (item && item->getType() != function::Invalid)
                  {
                      auto scaledPixMap = this->PixmapList[(int)item->getIconType()].scaled(QSize(32,32));
                      return QVariant(scaledPixMap);
                  }
              }
              break;
          }
          return QVariant();
      }
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Tater

      • Start by demonstrating what value this->VisiblePixmapList[(int)item->VisibilityIcon] has. It's probably correct, but we/you don't know that for sure till you print it out.

      • Use break statements correctly and consistently in your switch statement.

      • You are returning a QPixmap for DisplayRole. Where does Qt say you can do that? DisplayRole has to resolve to a string, https://doc.qt.io/qt-6/qt.html#ItemDataRole-enum

      Qt::DisplayRole 0 The key data to be rendered in the form of text. (QString)

      QPixmap does not, so probably comes out empty. I have not tried it, but from that page don't you want:

      Qt::DecorationRole 1 The data to be rendered as a decoration in the form of an icon. (QColor, QIcon or QPixmap)

      ?

      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