QTreeView and QTableView dynamic changes
Dynamically adding items to QTreeView and QTableView Create the UI as follows, with the treeview on the left hand side and the table view on the right hand side. Notes The header file contains the models and the selection models for the tree view and the table view: QStandardItemModel * treeViewModel ; QItemSelectionModel * treeViewSelectionModel ; QItemSelectionModel * tableSelectionModel ; QStandardItemModel * tableModel ; In the .cpp file, the tree view models and table view models are set as the models for the selection models. treeViewSelectionModel -> setModel ( treeViewModel ) ; tableSelectionModel -> setModel ( tableModel ) ; The following code illustrates how to dynamically add a new row to the treeview. void MainWindow :: updateTreeView ( ) { QStandardItem * newRow = new QStandardItem ( QString ( "inserted row" ) ) ; QList < QStandardItem * > newRows ; newRows . append ( newRow ) ; aut...
Comments
Post a Comment