QGraphicScenes and Delegates

July 31, 2007 – 7:34 pm

Ian writes some more:

In yesterday’s blog I talked about my issue of wanting to use (animated) GraphicsView’s in an Interview system for Amarok’s playlist. Ivan Čukić pointed me to a 2006 Trolltech Developer Days presentation about Advanced Item View. The presenter did show a pretty brute force way of doing animations in delegates, by just firing a timer every 40 ms. I tried this out two different ways.

First was similar to how he did it, firing a timer. It was not to my great surprise that this resulted in 30% CPU time for just one row needing to be animated, and it went up from there as additional rows were added It actually still looked and reacted fine though, so before I noticed the CPU usage I was feeling like I had cracked the case. :)

Then I tried it by connecting (indirectly, since I had to translate a QGraphicsScene into a QModelIndex) QGraphicsScene::sceneRectChanged to QAbstractItemView::update. However this didn’t work. Apparently QGraphicsScene doesn’t consider a flashing cursor as a scene change worth mentioning?

So now I’m basically back to where I was. Except the presentation did hold out another possibility of subclassing QAbstractItemView and then doing setViewport. This is what he did for the QGLWidget views that he made (instead of just writing a view from scratch). However its not quite clear to me what the QAbstractItemView provides when you override the viewport. More importantly none of the examples had scrolling, so they just painted the whole area all the time. And figuring that out is the biggest issue with perhaps using a QGraphicsView (whether by itself or as a viewport of a QAbstractItemView.)

More Playlist Details
Benjamin Meyer had a few questions about the playlist that I’ll address here:

  • I think Ben you know what the playlist does. :) The user queues up music to listen to and can also edit their tags.
  • I see no reason for multiple views.
  • Animations - yes. I don’t know if I’ll have time to do cool animations this summer, but I do want to have a framework in place where someone could implement nifty animations easily.
  • Editing - currently the reason I want to get animations to work. Users can do some basic bulk tag editing using the playlist.
  • As far as what the playlist looks like, its the thing on the right in Nikolaj’s most recent blog. In the future we want to do more complicated things such as grouping tracks from the same albums together.
  • Each row is a single cell, so the entire row is drawn in a single delegate paint. So the view itself is a fairly basic subclass of QListView.
  1. 4 Responses to “QGraphicScenes and Delegates”

  2. Can’t you just have very lightweight objects in a QGraphicsScene? They only really need to store a handle to the file which wouldn’t take much space and then you can have cache/uncache functions for when they get near the view. Also you’ll probably want a custom index as they are all in a line.

    By Tim on Jul 31, 2007

  3. Tim you mean ditch QListView and create a Interview-view using QGraphicsView? Yea I’m actually thinking doing something like this. I’ll just quote myself so I don’t have to type it again. :)

    [10:07] icefox: I thought of a new scheme as I was waking up. (I find during-wakeup to be a very creative part of the day, doesn’t mean the idea is any good though)
    [10:07] in the “QGraphicsView that uses a model to display data” idea
    [10:09] I subclass QGraphicsItem and in the paint method it would create QGraphicsTextItem’s, etc, normal QGV stuff
    [10:09] and ask the model for what info to put in them
    [10:09] so this QGraphicsItem would contain the whole row
    [10:10] then it would call QGraphicsItem::paint and let it do its job of painting everything that had just been setup
    [10:11] then I could implement a garbage collection system of deleting these QGraphicsItems as they are scrolled out of view (only to be recreated when scrolled back over)

    By Ian Monroe on Aug 1, 2007

  4. Whatever you do, do _not_ just randomly start firing timers at 40ms.

    We’re trying to get better battery life, not worse. :)

    By Travis on Aug 1, 2007

  5. Well timers are an important part of animations. If its not me explicitly starting the timer, something else is.

    By Ian Monroe on Aug 2, 2007

Post a Comment