QTreeView QML plugin with QFileSystemModel
-
wrote on 12 Jul 2012, 19:59 last edited by
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.0TreeView { id: myTreeView allColumnsShowFocus: true }@
I get a QTreeView displayed looking like this:
!http://1.bp.blogspot.com/-dtR8D2YWe1s/T_8mm21zLFI/AAAAAAAACfw/8LURCRfSXss/s1600/TreeView01.jpg(QTreeView alone)!
However, when my main.qml looks like this:
@import QtQuick 1.1
import TreeView_Plugin 1.0Rectangle {
id:myRect
width: 400
height: 400TreeView { id: myTreeView allColumnsShowFocus: true }
}@
All I get is this...
!http://4.bp.blogspot.com/-VGPBBJWf4p0/T_8ou3OB0tI/AAAAAAAACf4/qIkQ4vfHN5U/s1600/QTreeTestBlankShot.jpg(QTreeView inserted in QML)!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:
@QGLWidget *glWidget = new QGLWidget(this);
setViewport(glWidget);
setViewportUpdateMode(QGraphicsView::FullViewportUpdate);@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!
-
wrote on 13 Jul 2012, 00:10 last edited by
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 -
wrote on 13 Jul 2012, 17:15 last edited by
@mbrasser Thanks for the quick reply! I believe you are correct sir. I am going about implementing that solution now. I will post back with my results.
Cheers!
-
wrote on 13 Jul 2012, 23:06 last edited by
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":http://ultraopengl.blogspot.com/2012/07/qtreeview-in-qtquickqml-implementation.html folks if you are interested in learning more.
Again. Thanks for the help!
Share the love
Cheers!
1/4