How can I implement multiselection in Qt in TreeView when user holds key CTRL on keyboard ?

Viewed 315
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    MyFileSystemModel model;
};

My file cpp

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    model.setRootPath(QDir::rootPath());

     ui->treeView->setModel(&model);
     ui->treeView->setSelectionMode(QAbstractItemView::MultiSelection);
     ui->treeView->setDragEnabled(true);
}

I used the MultiSelection property, but it works only when I click on items in treeview with mouse, I don't want to select a few items without pressing CTRL on keyboard. How can I check if user pressed CTRL and then select items ?

1 Answers
Related