July 12, 2012

ultramanjones ultramanjones
Lab Rat
8 posts

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:

  1. import QtQuick 1.1
  2. import TreeView_Plugin 1.0
  3.  
  4.  
  5.     TreeView {
  6.         id: myTreeView
  7.         allColumnsShowFocus: true
  8.  
  9.     }

I get a QTreeView displayed looking like this:

QTreeView alone

However, when my main.qml looks like this:

  1. import QtQuick 1.1
  2. import TreeView_Plugin 1.0
  3.  
  4. Rectangle {
  5.     id:myRect
  6.     width: 400
  7.     height: 400
  8.  
  9.     TreeView {
  10.         id: myTreeView
  11.         allColumnsShowFocus: true
  12.  
  13.     }
  14.  
  15. }

All I get is this…
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:

  1.     TreeView {
  2.         id: myTreeView
  3.         x: 15
  4.         y: 15
  5.         allColumnsShowFocus: true
  6.     }

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:

  1. QGLWidget *glWidget = new QGLWidget(this);  
  2. setViewport(glWidget);  
  3.  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!

3 replies

July 13, 2012

mbrasser mbrasser
Ant Farmer
452 posts

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

July 13, 2012

ultramanjones ultramanjones
Lab Rat
8 posts

@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!

July 14, 2012

ultramanjones ultramanjones
Lab Rat
8 posts

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!

 
  ‹‹ QML SoundEffect Element is too slow!      [SOLVED] Fails to load QML extension using Qt’s SVG module ››

You must log in to post a reply. Not a member yet? Register here!