0

I am using a QItemDelegate combined with the QTableView's IsUserCheckable flag to draw a centered checkbox column. All has been working fine until I have enabled row selection for the table.

When selection occurs, the blue selection background is the only thing painted, and the checkboxes are no longer seen.

The following is my code I use to paint the checkbox from within the delegate.

void CheckboxDelegate::drawCheck(QPainter* painter, QStyleOptionViewItem const& option, QRect const& rect, Qt::CheckState state) const
{
    QSize size = check(option, option.rect, Qt::Checked).size();
    QRect checkboxRect = QStyle::alignedRect(option.direction, Qt::AlignCenter, size, option.rect);
    QItemDelegate::drawCheck(painter, option, checkboxRect, state);
}

Any ideas as to why this is not painting correctly when a selection is made?

cweston
  • 11,297
  • 19
  • 82
  • 107
  • 1
    You really need to post more code. I'd guess your ordering is messed up and you're painting the blue background **after** you're painting the checkbox – Robert Dec 14 '10 at 21:29
  • This is the only relevant code that paints anything. I imagine the issue is related to the order my painting as you mentioned but I am unsure how to implement the proper steps at this point. Hoping someone can provide some more insight. – cweston Dec 15 '10 at 00:58

1 Answers1

0

It is difficult to be confident that my answer will help you because of the lack of code that is posted, but I think your problem is that the painter not only paints the QRect, but it also paints the QItemDelegate. This means that unless you specifically tell it what you want the color of the QRect to be, it will paint it to be the same color as the entire cell.

If this is true, then your QRect is still there, but is simply the same color as the rest of the contents of the cell.

You can change the color of the painter for the QRect by doing painter.setPen(QColor.red);

Again, I do not have much code to work off of, but if you want the check to be a different color, you need to set it to be a different color.

If you provide more code I could answer you more clearly.

Ryan
  • 74
  • 4