Checkable Qtreeview.

  • How ca I implement a checkable treeview?

  • Just attach a model with the Qt::ItemIsUserCheckable flag set for the indexes you want to be checkable

  • @VRonin could you please show me some example ?

  • #include <QApplication>
    #include <QTreeWidget>
    int main(int argc, char *argv[])
        QApplication app(argc,argv);
        QTreeWidget w;
        auto item1 = new QTreeWidgetItem(QStringList("0,0"));
        item1->setFlags(item1->flags() | Qt::ItemIsUserCheckable);
        auto item2 = new QTreeWidgetItem(QStringList("1,0"));
        item2->setFlags(item2->flags() | Qt::ItemIsUserCheckable);
        return app.exec();

    I use QTreeWidget (which derives from QTreeView) for convenience here but you can use whatever combination of model/view you prefer

Log in to reply

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