Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStandardItem::setAutoTristate(bool tristate)
QtWS25 Last Chance

QStandardItem::setAutoTristate(bool tristate)

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • joeQJ Offline
    joeQJ Offline
    joeQ
    wrote on last edited by
    #1

    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)
        :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);
    }
    
    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 ?

    Just do it!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      VRoninV 1 Reply Last reply
      0
      • SGaistS SGaist

        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.

        VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        @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 empty role parameter you will have to subclass QStandardItemModel and reimplement setData to make it work.

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved