[SOLVED]Registering fields from a QTreeView embedded in a QWizardPage
-
Hi all,
I'm trying to build a wizard. As a very first step, I need a directory selection from user. I decided to use a QTreeView to make it happen. The problem for me is registering a field that contains user selection. I need help to understand how to this since I did not manage to use the registerField() function in such a context.
Here is the code I use:
@directoryPage::directoryPage(QWidget *parent) :
QWizardPage(parent)
{
setTitle(tr("Selecting a directory"));QFileSystemModel *model = new QFileSystemModel(); model->setFilter(QDir::Dirs); model->setRootPath(QDir::homePath()); treeView = new QTreeView(); treeView -> setModel(model); treeView -> setRootIndex(model->index(QDir::homePath())); treeView -> hideColumn(3); treeView -> hideColumn(2); treeView -> hideColumn(1); treeView -> setSelectionMode(QAbstractItemView::SingleSelection); QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(treeView); setLayout(layout); //registerField("inputDirectory", treeView, model->filePath(treeView->selectionModel()->selectedIndexes()));
}
@Thanks a lot for your help :-)
-
Hi and welcome to devnet,
QTreeView doesn't have such a property to register with QWizardPage. However you could subclass QTreeView and add the property yourself.
Hope it helps
-
[quote author="SGaist" date="1408304832"]Hi and welcome to devnet,
QTreeView doesn't have such a property to register with QWizardPage. However you could subclass QTreeView and add the property yourself.
Hope it helps[/quote]
@SGaist, Thx. This could be a solution. I was just looking for something more straightforward. Will do if nothing else comes up. Cheers
If I need to implement you solution, my first guess would be:
- creating a class inheriting from QTreeView --> myQtreeView
- adding a QString *selectedDirectory as a property
- creating a private hasChanged() slot that "stores" the data
- connecting this slot to the currentChanged signal from QItemSelectionModel (the model being retrieved from QTreeView::selectionModel().
Sorry but I'm quite new to Qt. Do you think this is a correct strategy ?
Thanks again.
-
solved. Thanks.
-
Sorry I've lost track on this one. Nice you found out !
Just one thing, no need to allocate QString on the heap