我正在使用 QItemDelegate 结合 QTableView 的 IsUserCheckable 标志来绘制居中的复选框列。在我为表格启用行选择之前,一切都运行良好。
When selection occurs, the blue selection background is the only thing painted, and the checkboxes are no longer seen.
以下是我用来从委托中绘制复选框的代码。
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);
}
关于为什么在进行选择时无法正确绘制的任何想法?