Results 1 to 9 of 9

Thread: Custom C++-based QML components in Qt 5?

  1. #1
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Custom C++-based QML components in Qt 5?

    With the Qt 5 alpha release already out and the first production release coming in a few months, I'm wondering what is required to port existing Qt 4.x QDeclarativeItem-based visual classes to Qt 5. I know QQuickPaintedItem is included to facilitate this porting effort by providing the QPainter API similar to what QDeclarativeItem does today, but I'm wondering how custom visual C++-based QML components are developed in Qt 5. The documentation for QQuickItem does not list a virtual paint method as QDeclarativeItem does. If someone could describe what the overall process is for developing C++-based visual QML components in Qt 5 (and, even better, provide a trivial code example) I'd greatly appreciate it. So far I haven't found any information or examples on this topic and am very curious as to how custom painting will be accomplished in Qt 5/Qt Quick 2.

    Edit: I forgot to mention that I've seen the QQuickCanvas QML element that allows for an HTML5-like API for painting in QML. However, I'm interested in how painting is done in C++.

  2. #2
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Custom C++-based QML components in Qt 5?

    Perhaps the way to do this is not yet known/documented for Qt 5? I still can't seem to find information on this.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom C++-based QML components in Qt 5?

    Quote Originally Posted by fonzi337 View Post
    The documentation for QQuickItem does not list a virtual paint method as QDeclarativeItem does.
    There exists a virtual paint() method in QQuickPaintedItem.

    If someone could describe what the overall process is for developing C++-based visual QML components in Qt 5 (and, even better, provide a trivial code example) I'd greatly appreciate it.
    From what I see in general one reimplements QQuickItem::updatePaintNode().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Custom C++-based QML components in Qt 5?

    Thanks wysota. It looks like the documentation for updatePaintNode was updated with a code snippet that clarifies things. Unfortunately, the API for drawing in the Scenegraph seems a little less user-friendly than the QPainter API (for instance, the code snippet under http://doc-snapshot.qt-project.org/5...metrynode.html that shows how to draw a straight line is fairly involved). Hopefully the Scenegraph API will grow to include facilities to simplify these common operations (or perhaps they are available but just haven't been documented yet).

  5. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom C++-based QML components in Qt 5?

    Wait.. that ugly code snippet is just to draw a red line? WTF? If that's how you draw a single red line, what the hell does a real world functional item look like? I fully understand the limitations of a sequential rasterized paint system, but this stuff looks makes it seem Nokia is intentionally making C++ use more difficult.

    For perspective, here's how you draw a red line in traditional QPainter:

    painter->setPen(Qt::red);
    painter->drawLine(0, 0, width(), height());

  6. #6
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Custom C++-based QML components in Qt 5?

    Yeah, the API seems quite low-level (closer to OpenGL than high-level C++). Is it possible the QSGGeometryNode class is the wrong class to be looking at? I find it hard to believe that the highest-level drawing API provided for Qt 5 is what's found in QSGGeometryNode, but I haven't been able to find anything else so far.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Custom C++-based QML components in Qt 5?

    I'm sure we'll get QPainter API too, probably with a warning that this causes slowdowns compared to scene graph approach.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Oct 2011
    Posts
    35
    Thanked 9 Times in 3 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Custom C++-based QML components in Qt 5?

    In case anyone else is interested in this, I have found two small tutorials that show concrete examples of how custom C++-based elements are exposed to Qt Quick in Qt 5.

    http://doc-snapshot.qt-project.org/5...mgeometry.html
    http://wiki.qtlabs.org.br/projects/q...les/scenegraph

    These examples are unfortunately still pretty basic/simple, but they at least show the basics.

  9. #9
    Join Date
    Aug 2013
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Custom C++-based QML components in Qt 5?

    Quote Originally Posted by fonzi337 View Post
    In case anyone else is interested in this, I have found two small tutorials that show concrete examples of how custom C++-based elements are exposed to Qt Quick in Qt 5.

    http://doc-snapshot.qt-project.org/5...mgeometry.html
    http://wiki.qtlabs.org.br/projects/q...les/scenegraph
    The Qt documentation erasure fairy strikes again. Both links are now dead.

Similar Threads

  1. Replies: 2
    Last Post: 27th July 2011, 15:49
  2. Linker error when creating custom Property Browser components
    By stefanadelbert in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2010, 03:50
  3. Replies: 2
    Last Post: 30th July 2009, 04:58
  4. Custom Style based on Cleanlooks
    By Tux-Slack in forum Qt Programming
    Replies: 4
    Last Post: 21st September 2007, 10:22
  5. Replies: 1
    Last Post: 26th January 2007, 07:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.