Originally Posted by
aamer4yu
You will need to use your own delegate. Look for QItemDelegate and QStyledItemDelegate. In that you will need to set the position for check and draw.
Accturally, I don't know how to set the rect of the checkbox item. I use QTreeWidget with QStyledItemDelegate instead of QTreeView, you know, in Model-View, I can control every thing I need.
But in QTreeWidget, It seems not easy for handle this.
I wrote an example in my QStyleItemDelegate subclass,
{
Q_ASSERT(index.isValid());
// draw the check box
if ( index.column() == 2 )
{
return;
}
QStyledItemDelegate::paint(painter, opt, index);
}
void CMTreeDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
Q_ASSERT(index.isValid());
QStyleOptionViewItem opt = option;
// draw the check box
if ( index.column() == 2 )
{
return;
}
QStyledItemDelegate::paint(painter, opt, index);
}
To copy to clipboard, switch view to plain text mode
The check box still showen in the column. obviousely, the delegate can not control the rect of the Checkbox which created with
treeWidget->setItemWidget(subItem, 2, chkItem);
subItem->setTextAlignment(2, Qt::AlignHCenter);
Qt::CheckState chkState = (bNeedSync.toInt() == 1) ? Qt::Checked : Qt::Unchecked;
chkItem->setCheckState(chkState);
treeWidget->setItemWidget(subItem, 2, chkItem);
subItem->setTextAlignment(2, Qt::AlignHCenter);
Qt::CheckState chkState = (bNeedSync.toInt() == 1) ? Qt::Checked : Qt::Unchecked;
chkItem->setCheckState(chkState);
To copy to clipboard, switch view to plain text mode
Bookmarks