If you mean QDirModel, that is because i want to include those Windows "special folders", like "Desktop" and also I want to put in the volume names, because only C, D, E, F, G, H, I, J, M, R etc look weird and not so clear
I'm not sure but QFileSystemModel can be better in your case.
It's really not important what is in the tree, it's just I don't really manage to get it work
Here it is (screenshot attached):
//prepare model
model->appendRow(item);
model->appendRow(item);
item = item->child(0,0);
// or
QFileSystemModel *fsmodel = new QFileSystemModel(this);
fsmodel->setRootPath("/");
// set view
ui->comboBox->setView(tv);
// set model
// ui->comboBox->setModel(model);
ui->comboBox->setModel(fsmodel);
//prepare model
QStandardItemModel *model = new QStandardItemModel(ui->comboBox);
QStandardItem *item = new QStandardItem("item1");
model->appendRow(item);
item->appendRow(new QStandardItem("item2"));
item = new QStandardItem("item3");
model->appendRow(item);
item->appendRow(new QStandardItem("item4"));
item = item->child(0,0);
item->appendRow(new QStandardItem("item5"));
// or
QFileSystemModel *fsmodel = new QFileSystemModel(this);
fsmodel->setRootPath("/");
// set view
QTreeView *tv = new QTreeView(ui->comboBox);
ui->comboBox->setView(tv);
// set model
// ui->comboBox->setModel(model);
ui->comboBox->setModel(fsmodel);
To copy to clipboard, switch view to plain text mode
The only problem is that expanding treeview closes the popup.
For example if the QTreeView is not set as a view for the combo box, I can use the signal clicked(), but this is not working with the view set on the combo box. If I use the combo's currentIndexChanged() signal, selecting item 2 will return index 0, because item 2 is a child of item 1 at index 0. I'm really confused about this model/view thing
You can use QComboBox::currentText() to get currently selected text or maybe use QItemSelectionModel::currentChanged() from:
comboBox->view()->selectionModel()
comboBox->view()->selectionModel()
To copy to clipboard, switch view to plain text mode
(didn't try this).
Bookmarks