Important: Please read the Qt Code of Conduct -

Why i can't select different items in QTreeView

  • I can select only one item , i can't select my two rows for example:
    alt text

    I want to select my two rows in my treeview.
    Code mainwindow.cpp:

    //! [Quoting ModelView Tutorial]
    // modelview.cpp
    #include <QTreeView>
    #include <QStandardItemModel>
    #include <QStandardItem>
    #include "mainwindow.h"
    const int ROWS = 2;
    const int COLUMNS = 3;
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        treeView = new QTreeView(this);
        standardModel = new QStandardItemModel ;
        QList<QStandardItem *> preparedRow =prepareRow("first", "second", "third");
        QStandardItem *item = standardModel->invisibleRootItem();
        // adding a row to the invisible root item produces a root element
        QList<QStandardItem *> secondRow =prepareRow("111", "222", "333");
        // adding a row to an item starts a subtree
        QList<QStandardItem *> thirdRow =prepareRow("111", "222", "333");
        // adding a row to an item starts a subtree
    QList<QStandardItem *> MainWindow::prepareRow(const QString &first,
                                                    const QString &second,
                                                    const QString &third)
        QList<QStandardItem *> rowItems;
        rowItems << new QStandardItem(first);
        rowItems << new QStandardItem(second);
        rowItems << new QStandardItem(third);
        return rowItems;
    //! [Quoting ModelView Tutorial]

    Thanks in advance!

  • @Ratzz Thanks i solved using:


    i will check too:

  • @Ratzz for qtreewidget the example will be the same? because i'm using both and maybe will be the same thing?

  • @RIVOPICO said in Why i can't select different items in QTreeView:

    because i'm using both

    I did not get you.

Log in to reply