QTreeView QML plugin with QFileSystemModel
Hello everybody. I’m trying to incorporate a Model/View into an application using QTreeView, QFileSystemModel and qmlRegisterType to create the QTreeView plugin.
If my main.qml looks like this:
- import QtQuick 1.1
- import TreeView_Plugin 1.0
- TreeView {
- id: myTreeView
- allColumnsShowFocus: true
- }
I get a QTreeView displayed looking like this:

However, when my main.qml looks like this:
- import QtQuick 1.1
- import TreeView_Plugin 1.0
- Rectangle {
- id:myRect
- width: 400
- height: 400
- TreeView {
- id: myTreeView
- allColumnsShowFocus: true
- }
- }
All I get is this…

I am not able to insert the “TreeView” into the rest of my QML and I can’t figure out why.
If I try to add a property change to x, y, width or height, for example:
- TreeView {
- id: myTreeView
- x: 15
- y: 15
- allColumnsShowFocus: true
- }
I get error: Invalid property assignment: “x” is a read-only property
Of course I will post plenty more code if someone thinks they might be able to help.
The application already uses a QDeclarativeView with an OpenGL backend like so:
- setViewport(glWidget);
There is of course a bit more code involving setting the FileSystemModel, etc, but I don’t believe it is relevant. I am really quite baffled here. Obviously, I need the QTreeView to show within the rest of my QML or there really is no point.
If anyone could point me to a way to do this, I would very much appreciate it. I’m pretty new to Qt and I readily admit that I sometimes have no idea what is going on “under the hood”, especially when it comes to the whole MOC file paradigm.
Whatever way I can get this done is fine with me. I really thought the plugin (qmlRegisterType) method was the way to go, because I’m using it to create an OpenGL window for animations in a separate part of the app, but, as you can see, it ain’t working.
Thanks for your help!
3 replies
Hi,
You’ll need to wrap the QTreeView in a QGraphicsProxyWidget to use it in a mixed QML scene. The C++ Extensions: QWidgets example at http://doc-snapshot.qt-project.org/4.8/declarative-cppextensions-qwidgets.html gives an example of this technique.
Regards,
Michael
Ok, I got at least the preliminary workings of this implemented. It still needs all kinds of work to be fully functional, but see here [ultraopengl.blogspot.com] folks if you are interested in learning more.
Again. Thanks for the help!
Share the love
Cheers!
You must log in to post a reply. Not a member yet? Register here!


