Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-73655

QTableView Not Rendering Icons Correctly

XMLWordPrintable

    • Windows
    • e771e5e2d (dev), 82b3f3fba (6.7), a09661402 (tqtc/lts-6.5)

      When using an Icon in the decoration role of a QTableView it does not render properly. It appears to render a different size than the intended one. Which is especially visible for something like the check mark from the apply button icon. When using a pixmap though for the appropriate size, the icon is rendered correctly.

      A simple example:

      class Model : public QAbstractTableModel {
      
          int rowCount(const QModelIndex &parent = QModelIndex()) const override {
              return 1;
          }
          int columnCount(const QModelIndex &parent = QModelIndex()) const override {
              return 2;
          }
      
          QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override {
              if( role == Qt::DecorationRole ) {
                  QIcon icon = QApplication::desktop()->style()->standardIcon( QStyle::SP_DialogApplyButton );
      
                  switch( index.column() ) {
                  case 0:
                      return icon;
                  case 1:
                      return icon.pixmap(QSize(16, 16));
                  }
              }
      
              return QVariant();
          }
      };
      

       Then simply set the model:

          ui->tableView->setIconSize(QSize(16, 16));
          ui->tableView->setModel(new Model());
      

      As seen on the image below:

        1. renderissue.png
          4 kB
          Mark R
        2. project.zip
          3 kB
          Mark R
        3. misrendered.png
          3 kB
          Mark R
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            skl131313 Mark R
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes