Qt6 - Svg file image drawn using delegate paint method has scaling issue

28 views Asked by At

I see that the checkbox svg image drawn using the delegate paint method (subclassed from QStyledItemDelegate) in a QTreeView column looks different than drawn using the css file. I mean the borders drawn are thin.

enter image description here

In the attached picture, column B checkbox is drawn using the svg file declared in the css file which is as expected. Column A is drawn using the paint method and I expect it to look same as the column A.

When the monitor display scale settings is 125%, the drawn image in column A using the the below paint code looks the same as the column B and is ok. But when the settings is 100%, the column A image looks thin and does not look same as column B which is not good.

How do I resolve this issue ? I am not sure if I am missing anything here. Thanks in advance. Below is the snippet of my paint method implementation.

void ModelDelegate::paint(
       QPainter* painter,
       const QStyleOptionViewItem& option,
       const QModelIndex& index) const
    {
      ....
     else if (index.column() == Model::DisabledColumn)
          {
            painter->save();
            QStyleOptionViewItem option_copy(option);
            option_copy.icon = QIcon(":/icon/checkbox_empty.svg");;
    
            QRect rect = option_copy.rect;
            rect.adjust(3, 0, 0, 0);
            option.widget->style()->drawItemPixmap(
            painter, rect, Qt::AlignLeft | Qt::AlignVCenter, icon.pixmap(16, 16));
            painter->restore();
            return;
          }   
    }
0

There are 0 answers