Nominate our 2022 Qt Champions!

Move multiple selected items from Qtreeview to QListBox

  • I want to move selected items from QTreeview (populated by QFileSystemModel) to a QListBox. I have managed to get all selected items in a QMdelIndex list, but I cant add this to QListbox since QListBox->addItems(QStringList) only accepts QStringList.
    Please guide me through.

    @QItemSelectionModel selectiveModel=ui->treeView->selectionModel();
    QModelIndexList list=selectiveModel.selectedIndexes();

  • You can't. Not directly. An item in one view is not a separate object that you can just stick in another view.

    You'll have to add what the other view represents, or build some kind of proxy that represents the selected items from one view as a new model, that you can set on your list view.

  • Thanks a lot for the suggestion

  • Which model should I create? A QProxyModel or something..

  • It depends on the kind of interaction you're really after. You're not giving us enough information on what you want to do exactly. Also, I guess it depends on your level of Qt knowledge and C++ proficiency as well.

  • I am sorry for less info, I want to add multiple selected items from a QTreeView to a QListBox, as right now I am abe to add one selected item from the QTreeView to QListBox.I am adding the item by double clicking on the item in the QTreeView.
    I am not an expert in c++ nor in Qt.

Log in to reply