3

We need a tree view with File system and check boxes in QT. Is there any way to achieve that?

The tree we need would look something like below:

enter image description here

UPDATE:

I am able to achieve it with subclass of QFileSystemModel. Still have few challenges, but at least subclass is working. Below is the code if anyone needs it. Below is the link to the code -

https://drive.google.com/file/d/1qViZ3iEW2pV2th0jQhzneDL14SEhIgS0/view?usp=sharing

The pending work is to apply a wait cursor (or make treeview uneditable when the check/uncheck is taking place).

PS: It will take a lot of time if root node is checked.

Nitin Jain
  • 289
  • 2
  • 9
  • You can probably subclass [QFileSystemModel](https://doc.qt.io/qt-5/qfilesystemmodel.html) and use it with a `TreeView`/`QTreeView` . Checkboxes are not so hard to implement. – MasterAler Jan 30 '20 at 22:55
  • Thanks @MasterAler for the suggestion :) – Nitin Jain Feb 01 '20 at 07:17
  • @MasterAler I was able to extend QFileSystemModel and able to get working treeview with Qt Form application, but the same is not working with Qt Quick control treeview, as Qt Quick treeview works in a bit different manner, and I am struggling there. Do you have any pointers related to Qt Quick treeview as well for the same work? – Nitin Jain Feb 01 '20 at 15:53

1 Answers1

2

Well, all of that can be achieved with minimal customizations of built-in classes, actually those checkboxes is almost the only thing that has to be done yourself.

  • QFileSystemModel already provides a proper model for displaying the current filesystem contents, it can be subclassed
  • As for QML, the best demo is already provided by Qt, check the File System Browser Example. This example uses some deprecaded Qt functionality, but still it shows the basic concept.
  • The modern techniqes can be also found in the answers to the following question: Qt File Browser based on QML

Hopefully, all that helps you, good luck!

MasterAler
  • 1,614
  • 3
  • 23
  • 35
  • Hi @MasterAler , Tahnks for the information. I have already gone through the File System Browser Example. The issue I am facing is to have checkbox and text in single column (though that I can achieve by using item delegate of treeview), and kick off data changed event (to eventually call setData method of extended FileSystemModel) on button check/uncheck. I am trying to work it out. Thanks for the help. – Nitin Jain Feb 02 '20 at 08:12