Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Huge TreeView hack



  • I am trying to finish a dialog that uses a filesystem related TreeView object. I use the QFileSystemModel (an object derived from this) for my model. I found during testing that I cannot get the TreeView to display some directories both on windows and linux. It is like it would not fetch them. So while testing I hooked the same model and selected index into a ListView/DelegateModel like this:

                                   ListView {
                                        id: hacky_listview
                                        visible: false
                                        height: 100
                                        width: 100
    
                                        model: hacky_delegatemodel
    
                                        DelegateModel {
                                            id: hacky_delegatemodel
    
                                            model: treeview.model
    
                                            rootIndex: treeview.selectedindex
    
                                            onRootIndexChanged: {
                                                //rootIndex = treeview.selectedindex
                                            }
    
                                            delegate: Item {
                                                height: 10
                                                width: 100
    
                                                Text {
                                                    text: fileName
                                                }
                                            }
                                        }
                                    }
    

    I found when I did this that the TreeView all of a sudden started showing all entries! All I did was add a consumer of the same model. So as the name of my object suggest I have this hacky solution to get the model to populate itself properly. I have no idea where the problem lies, but I suspect TreeView is not doing something that the ListView/DelegateModel does.

    I am using Qt 5.12.x so I am still using the QuickControls 1 TreeView. I do not know if the newer TreeView from the later version of Qt will fix this issue. We are standardized on 5.12.x for now. I did search the bug reports for Qt and could not find anything related to this issue. I am curious if anyone else has noticed this problem.


Log in to reply