Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTreeWidgetItem checkState() signal and slot?



  • How do I implement a QTreeWidgetItem checkState() signal and slot?

    I have a child QTreeWidgetitem that I want to deliver a signal if it is checked or unchecked, so the parent treewidgetitem will uncheck too. Sort of like a full packge install, that unchecks the parent box if just one of the child boxes are unchecked.

    I'm learning signals and slots implementation without the ui, just now.


  • Lifetime Qt Champion

    Hi,

    You don't do it on the items (they are not QObject), but in the QTreeWidget using e.g.
    @QTreeWidget::itemChanged ( QTreeWidgetItem * item, int column )@

    Connect that signal to a custom slot and handle there the modification of your items.

    Hope it helps



  • TWI->setCheckState(column, Qt::Checked);
    connect(ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(treeWidgetItemChanged(QTreeWidgetItem*, int)));
    
    void MainWindow::treeWidgetItemChanged(QTreeWidgetItem *TWI, int column)
    {
        if (TWI->checkState(column) == Qt::Checked){
            ......
        } 
    }
    

Log in to reply