Solved Why i can't select different items in QTreeView
-
I can select only one item , i can't select my two rows for example:
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); setCentralWidget(treeView); 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 item->appendRow(preparedRow); QList<QStandardItem *> secondRow =prepareRow("111", "222", "333"); // adding a row to an item starts a subtree preparedRow.first()->appendRow(secondRow); QList<QStandardItem *> thirdRow =prepareRow("111", "222", "333"); // adding a row to an item starts a subtree preparedRow.first()->appendRow(thirdRow); treeView->setModel(standardModel); treeView->expandAll(); } 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!
-
@RIVOPICO
I think this is what you looking for http://doc.qt.io/qt-4.8/qabstractitemview.html#selectionMode-prop
-
@Ratzz Thanks i solved using:
treeView->setSelectionMode(QAbstractItemView::MultiSelection); treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
i will check too:
http://doc.qt.io/qt-4.8/qabstractitemview.html#selectionMode-prop -
@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.