Delegate customization issue

  • I am overriding the paint(...) function of QStyledItemDelegate as follows. I just want to display a red cross in all cells of a column on a QTableView. (I am applying this delegate for 3rd column only) What is wrong with the code? I am not able to see the cross mark in the cell. Instead I can see a red spot at top left corner of the table

    void CrossDelegate::paint(QPainter *painter,
    const QStyleOptionViewItem &option,
    const QModelIndex &index) const
    painter->setRenderHint(QPainter::Antialiasing, true);
    painter->drawLine(QPointF(0.0, 1.0) ,QPointF(1.0, 0.0) );
    painter->drawLine(QPointF(0.0, 0.0) ,QPointF(1.0, 1.0) );

  • Qt Champions 2017

    @qmad said:

    Hi and welcome
    the painter is for whole widget. whole area.
    there should be a option.rect that should be the cell area.
    so the 0,0 would be rect.left,

    here is an example shown:

  • @mrjj

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.