QTreeWidget and QFileSystemModel

2019-09-06 13:37发布

问题:

Please tell me how to connect to QFileSystemModel QTreeWidget simply function SetModel() not support QFileSystemModel but only QAbstractItemModel, but I need to work with files and for these purposes QAbstractItemModel not fit, I would like to open files in directories climb QTreeWidget. Thanx

回答1:

setModel is a private function in QTreeWidget. To use it, you could create a custom TreeWidget class that inherits QtreeWidget and QTreeView, create a public function setModel(QAbstractItemModel *model) and in it call the QTreeView setModelfunction like so:

 TreeView::setModel(QAbstractItemModel *model){
      QTreeView::setModel(model); 
 }