frankb
3rd January 2014, 17:46
Hello,
how can I connect a QSqlTableModel to a QTreeView in such a way, that only selected items (selected via code) are shown in the QTreeView? Usually I would connect the model to the QTreeView like so:
treeView = new QTreeView();
treeView->setModel(model);
This results in the QTreeView displaying all rows of the underlying SQL table. I would like to be able to only let the QTreeView display items that are set by some function:
void MainWindow::addEntry(QModelIndex index)
{
// treeView does know the model, and thus can handle the QModelIndex internally
treeView->addItem(index);
}
My first intention was to use QTreeWidget instead and manage all items manually. But I would really like to use the same model for another widget. Once the data in the second widget is changed, the QTreeView should also be updated automatically. If I would use a QTreeWidget instead, I would have to tell the other widget's parent (main window) about any changes, and manually propagate them to the QTreeView (and other potential widgets that are not connected to the model). Is there any way to achieve this behavior with the model/view approach?
Thank you!
how can I connect a QSqlTableModel to a QTreeView in such a way, that only selected items (selected via code) are shown in the QTreeView? Usually I would connect the model to the QTreeView like so:
treeView = new QTreeView();
treeView->setModel(model);
This results in the QTreeView displaying all rows of the underlying SQL table. I would like to be able to only let the QTreeView display items that are set by some function:
void MainWindow::addEntry(QModelIndex index)
{
// treeView does know the model, and thus can handle the QModelIndex internally
treeView->addItem(index);
}
My first intention was to use QTreeWidget instead and manage all items manually. But I would really like to use the same model for another widget. Once the data in the second widget is changed, the QTreeView should also be updated automatically. If I would use a QTreeWidget instead, I would have to tell the other widget's parent (main window) about any changes, and manually propagate them to the QTreeView (and other potential widgets that are not connected to the model). Is there any way to achieve this behavior with the model/view approach?
Thank you!