Re: QCheckBox in QTreeWidget
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.
Re: QCheckBox in QTreeWidget
Quote:
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,
Code:
{
Q_ASSERT(index.isValid());
// draw the check box
if ( index.column() == 2 )
{
return;
}
QStyledItemDelegate::paint(painter, opt, index);
}
The check box still showen in the column. obviousely, the delegate can not control the rect of the Checkbox which created with
Code:
treeWidget->setItemWidget(subItem, 2, chkItem);
subItem->setTextAlignment(2, Qt::AlignHCenter);
Qt::CheckState chkState = (bNeedSync.toInt() == 1) ? Qt::Checked : Qt::Unchecked;
chkItem->setCheckState(chkState);
Re: QCheckBox in QTreeWidget
Am not sure how to do with QStyledItemDelegate. But with QItemDelegate you need to set the rect in option.,, and then call drawCheck.
Look into Qt source code,,, you will get an idea of what calls are done to do the drawing