PDA

View Full Version : QGraphicsView inside of QAbstractItemView viewport problem



koosh
29th June 2008, 00:08
Hi. I've got a model/view architecture with several custom QTreeView / QTableView views and I'd like to add a QGraphicsView of this model also. My approach was to subclass QAbstractItemView, adding a QGraphicsScene and QGraphicsView to this class. Any updates to the model will then add/modify the associated QGraphicsItems in the graphics scene.

I'm just starting out on this part, and the problem is that I can't get the QAbstractItemView viewport to properly display the QGraphicsView. My QGraphicsView is constructed with the QAbstractItemView as a parent widget, and then I setViewport(graphicsview). The graphics view is displayed in the QAbstractItemView window, but as a small rect in the upper corner. If I scale the GraphicsView it changes in size, but scrolling doesn't work. If I resize the window, the graphicsview doesn't resize or scroll. What am I missing here?

estan
22nd February 2009, 14:26
I'm kind of in the same situation and would love to hear from somebody who has used QGraphicsView in a QAbstractItemView subclass.
My reason for trying this is that I essentially want to create a pimped up list view where each item can be "flipped" over with an animated effect, kind of like a rotating square rod. Ugly mockup:

http://dose.se/flipmock.png

Bjoern
26th February 2009, 10:12
@estan:

Why using a QGraphicsView for this ?
I can't think of a clean solution of this, but I'm just beginning to dig deep into QGV yet.

My suggestion is to use a custom delegate, which handles the animation.
This is the way of customizing Views is intended by Troll (*err* ... Nokia ;) ), and I've already seen fluid animations using this approach on X11/Linux.

@koosh (even though your post is really old):

I don't expect this to work, your basic problem are the event handlers of GraphicsView and ItemView.
Both are subclasses of QAbstractScrollArea, which generates the ViewportEvents which are responsible for most stuff in ItemView AND GraphicsView.
And your'e stacking both, so there will be events which are handled by the ItemView, others are by the GraphicsScene, this simply can't work w/o custom subclasses.

But I don't get why you want to do this stuff ...
Do you really need to draw (model based) items which can handle Interaction and Animation of the displayed Scene ?
I'd suggest to make a snapshot of the scene into a QPixmap and display a thumbnail in your item view.

Hope this is useful somehow :rolleyes:

greetings,
Bjoern