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. Why i can't select different items in QTreeView
Forum Updated to NodeBB v4.3 + New Features

Why i can't select different items in QTreeView

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • RIVOPICOR Offline
    RIVOPICOR Offline
    RIVOPICO
    wrote on last edited by
    #1

    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);
        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!

    1 Reply Last reply
    0
    • RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #2

      @RIVOPICO
      I think this is what you looking for http://doc.qt.io/qt-4.8/qabstractitemview.html#selectionMode-prop
      alternate text

      --Alles ist gut.

      RIVOPICOR 2 Replies Last reply
      2
      • RatzzR Ratzz

        @RIVOPICO
        I think this is what you looking for http://doc.qt.io/qt-4.8/qabstractitemview.html#selectionMode-prop
        alternate text

        RIVOPICOR Offline
        RIVOPICOR Offline
        RIVOPICO
        wrote on last edited by
        #3

        @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

        1 Reply Last reply
        0
        • RatzzR Ratzz

          @RIVOPICO
          I think this is what you looking for http://doc.qt.io/qt-4.8/qabstractitemview.html#selectionMode-prop
          alternate text

          RIVOPICOR Offline
          RIVOPICOR Offline
          RIVOPICO
          wrote on last edited by
          #4

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

          RatzzR 1 Reply Last reply
          0
          • RIVOPICOR RIVOPICO

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

            RatzzR Offline
            RatzzR Offline
            Ratzz
            wrote on last edited by
            #5

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

            because i'm using both

            I did not get you.

            --Alles ist gut.

            1 Reply Last reply
            0

            • Login

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