QStandardItem::setAutoTristate(bool tristate)
-
Do I must be use the
setAutoTristat
inQTreeWidget
class ?I want to finish one tree widget and every top item has check box. From Qt help manual. I find
void QStandardItem::setAutoTristate(bool tristate) Determines that the item is tristate and controlled by QTreeWidget if tristate is true. This enables automatic management of the state of parent items in QTreeWidget (checked if all children are checked, unchecked if all children are unchecked, or partially checked if only some children are checked).
It is my want. but I don't know how to use it.
I used it in
QTreeView
, but not work. like below code snippet:TreeView::TreeView(QWidget *parent) :QTreeView(parent) { int row=0,columns = 1; _model = new QStandardItemModel(row,columns,this); setModel(_model); QStringList headerlabels; headerlabels << tr("name"); _model->setHorizontalHeaderLabels(headerlabels); QStandardItem* item; QStandardItem* item_1D; item_1D = new QStandardItem(tr("1D")); item_1D->setCheckable(true); item_1D->setTristate(true); item_1D->setAutoTristate(true); /// Not work when i changed chindren item checked state _model->appendRow(item_1D); item = new QStandardItem(tr("1D-00")); item->setCheckable(true); item_1D->appendRow(item); item = new QStandardItem(tr("1D-01")); item->setCheckable(true); item_1D->appendRow(item); item = new QStandardItem(tr("1D-02")); item->setCheckable(true); item_1D->appendRow(item); }
- did i must use
setAutoTristate
inQTreeWidget
? - if 1 is yes, and, how to use
setAutoTristate
? - is there simple demo about used tristate ?
- did i must use
-
Hi,
From what I can see it's a feature that's used by QTreeWidget so you'll likely have to read the QTreeWidget sources to see how it's implemented there.
-
@SGaist said in QStandardItem::setAutoTristate(bool tristate):
read the QTreeWidget sources to see how it's implemented there
https://code.woboq.org/qt5/qtbase/src/widgets/itemviews/qtreewidget.cpp.html#1730
As you can see the feature is implemented in the model. Since QStandardItemModel emits
dataChanged
with an emptyrole
parameter you will have to subclass QStandardItemModel and reimplementsetData
to make it work.