QStandardItem::setAutoTristate(bool tristate)

  • Do I must be use the setAutoTristat in QTreeWidget 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)
        int row=0,columns = 1;
        _model = new QStandardItemModel(row,columns,this);
        QStringList headerlabels;
        headerlabels << tr("name");
        QStandardItem* item;
        QStandardItem* item_1D;
        item_1D = new QStandardItem(tr("1D"));
        item_1D->setAutoTristate(true); /// Not work when i changed chindren item checked state
        item = new QStandardItem(tr("1D-00"));
        item = new QStandardItem(tr("1D-01"));
        item = new QStandardItem(tr("1D-02"));
    1. did i must use setAutoTristate in QTreeWidget ?
    2. if 1 is yes, and, how to use setAutoTristate ?
    3. is there simple demo about used tristate ?

  • Lifetime Qt Champion


    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.

  • Qt Champions 2018

    @SGaist said in QStandardItem::setAutoTristate(bool tristate):

    read the QTreeWidget sources to see how it's implemented there


    As you can see the feature is implemented in the model. Since QStandardItemModel emits dataChanged with an empty role parameter you will have to subclass QStandardItemModel and reimplement setData to make it work.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.