Results 1 to 8 of 8

Thread: QML or QGraphicsView?

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QML or QGraphicsView?

    I'm going to develop a game that relies heavily on animation, hit-testing, state changing, creating/moving/destroying many objects.
    Two/four/six/eight views with the same scene and tile based map.
    So, should I use QML or QGraphicsView?

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

    Default Re: QML or QGraphicsView?

    Well... strictly speaking QML (or rather QtQuick) is also QGraphicsView so you'll be using Graphics View anyway. If you want multiple views on one scene then as far as I remember you can't use Qt Quick, it's a one-to-one (or one-to-zero) relation only.
    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.


  3. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QML or QGraphicsView?

    Why does it seem that QML is faster? When I use the Qt Demo QML apps, they work very smooth. But when I use graphics view, updating items positions is so slow...
    I think using setPos() might be the culprit. Should I subclass QGraphicsSvgItem and use it's paint() to update it's position?
    I saw this example and they subclass a QWidget, reimplement paintEvent() and paint an updated QRect to reflect the items position. Would that help with the speed of QGraphicsView?

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QML or QGraphicsView?

    I guess with QML comes more of javascript...
    Most examples I have seen use javascript for function implementation.

    While coding in graphicsview, you will be directly using Qt classes. QML also finally converts the code to Qt graphicsview code.

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

    Default Re: QML or QGraphicsView?

    Quote Originally Posted by been_1990 View Post
    Why does it seem that QML is faster?
    Because QtQuick is fine tuned to some specific use cases.
    But when I use graphics view, updating items positions is so slow...
    Because your code is not optimal.

    I think using setPos() might be the culprit. Should I subclass QGraphicsSvgItem and use it's paint() to update it's position?
    No, definitely not. That would break the whole architecture.
    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.


  6. #6
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QML or QGraphicsView?

    Because your code is not optimal.
    What would make my code optimal? The code I use gets the mouse position increment(from raw input), then sets the item with setPos():

    Qt Code:
    1. QGraphicsSvgItem * redPointer = new QGraphicsSvgItem(QCoreApplication::applicationDirPath().append("/redPointer.svg"));
    2.  
    3. void Widget::mouseCoord(int x, int y){
    4. redPointer->setPos(QPointF::QPointF(redPointer->x()+x/3, redPointer->y()+y/3));
    5. }
    To copy to clipboard, switch view to plain text mode 

    But that gets awfully slow , any pointers on how to optimize?

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

    Default Re: QML or QGraphicsView?

    Quote Originally Posted by been_1990 View Post
    What would make my code optimal?
    Fixing the slowest parts of it. What the slowest parts are depends on the use case.

    The code I use gets the mouse position increment(from raw input), then sets the item with setPos():
    setPos() is not the bottleneck.

    But that gets awfully slow , any pointers on how to optimize?
    I'd start by enabling the item cache.
    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
    Nov 2009
    Location
    Sacramento, CA
    Posts
    24
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QML or QGraphicsView?

    I would also check QGraphicsScene and see what you have set on your ItemIdexMethod. If your scene is highly dynamic and you have BspTreeIndex enabled, it could cause a slow down there.

Similar Threads

  1. About QGraphicsView
    By paolom in forum Qt Programming
    Replies: 5
    Last Post: 28th September 2010, 04:32
  2. QGraphicsView
    By Maluko_Da_Tola in forum Newbie
    Replies: 1
    Last Post: 20th July 2010, 18:56
  3. QGraphicsView
    By Maluko_Da_Tola in forum Newbie
    Replies: 11
    Last Post: 19th July 2010, 08:15
  4. QGraphicsView
    By Yayati.Ekbote in forum Newbie
    Replies: 2
    Last Post: 4th March 2010, 15:10
  5. QGraphicsView
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2007, 08:00

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
  •  
Qt is a trademark of The Qt Company.