Results 1 to 6 of 6

Thread: animations in Interview Delegates

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default animations in Interview Delegates

    FIrst off, has anyone heard of anyone using a QGraphicsScene to paint a QAbstractItemDelegate? Thats the heinous thing I'm doing... but anyways I think I can make my question more general.

    How do you perform animations in a delegate? To initiate repaints you normally just have the model call emit dataChanged. But thats pretty crude (repaints the entire row when all you might need is a blinking cursor) and is in the model when really you'd like the delegate to make the decision for repainting due to an animation (since no data changed after all).

    Note I'm talking about when your subclassing QAbstractItemDelegate and overriding paint()... I can't use any QWidget-based editor stuff.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: animations in Interview Delegates

    FIrst off, has anyone heard of anyone using a QGraphicsScene to paint a QAbstractItemDelegate? Thats the heinous thing I'm doing... but anyways I think I can make my question more general.
    No, not really.
    First of all, you need a graphics view to display a scene.
    I think this could be achieved by setting the item widget to a graphics view (in a list widget or tree widget ), but that is a performance killer, especially if you have a lot of items.

    How do you perform animations in a delegate? To initiate repaints you normally just have the model call emit dataChanged. But thats pretty crude (repaints the entire row when all you might need is a blinking cursor) and is in the model when really you'd like the delegate to make the decision for repainting due to an animation (since no data changed after all).
    You could make use of the QTimeLine class for animations.
    Everything should be done internally, in the delegate.
    You will need at least one slot for the time line trigger.
    Also you would need a reference to the parent view, for refreshing purposes. The delegate update would be too hard to do.
    Too hard and I don't really know what the performance would be.

    Another solution and probably the best is to use widgets for the items and forget about delegates.
    Widgets are really easy to paint and you can trigger updates manually very easy.


    Regards

  3. #3
    Join Date
    Mar 2007
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Re: animations in Interview Delegates

    Have you ever used widgets in Interview? I don't think its possible easily. I've talked to a developer who has done it and he told me quite clearly that it has sucked his life. QAbstractItemView::setIndexWidget says: "This function should only be used to display static content within the visible area corresponding to an item of data. If you want to display custom dynamic content or implement a custom editor widget, subclass QItemDelegate instead."

    I'm using QGraphicsScene::render to paint on QAbstractItemDelegate::paint calls.

    The delegate update would be too hard to do.
    But how would you do it? :)

    Really just ignore that I'm using a delegate, or a QGraphicsScene or whatever. I'm certainly open to other ways of doing it.

    I simply don't see how to ever put animations in a QAbstractListView.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: animations in Interview Delegates

    I meant using QListWidget/QTreeWidget and setItemWidget. If you want to use the base views instead then you can reference the code in Qt.
    I still believe a widget would be best.

    I'm using QGraphicsScene::render to paint on QAbstractItemDelegate:aint calls.
    I think the overhead is too big for what you are trying to achieve.
    You can do the same thing and with less resources by using a QPixmap (think of it as a frame )and a QPainter. Paint whatever you need in the pixmap and display it in the delegate. Next, do the same for the next frame. I think you could use QTimeLine here and do the drawing relative to the remaining time.

    Really just ignore that I'm using a delegate, or a QGraphicsScene or whatever. I'm certainly open to other ways of doing it.
    Well, I can't just ignore it. .

    I simply don't see how to ever put animations in a QAbstractListView.
    Do you mean QAbstractItemView? I don't think QAbstractList view exists.


    Regards

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: animations in Interview Delegates

    Here's another one:
    What about using item editors(widgets), that are not really editors?
    This way you could really create your custom widget with a custom paint event.
    Once you set it in an item, just let it paint itself. It is all about how you implement the paintEvent.

    Regards

  6. #6
    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: animations in Interview Delegates

    Doing animations in Item-views is trivial. Create a custom slot and connect it to a signal which you want to serve as a trigger for the animation (like dataChanged or whatever else you need). In the slot use a QTimeLine that will signal each next frame of the animation and connect it to a routine that will update the view. In the painting routine of the delegate just check which frame you're currently drawing and... paint it.

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.