PDA

View Full Version : Subclassing QAbstractItemView



psih128
11th October 2008, 13:40
Hi

All last week I was struggling to learn the Model-View framework and find a way to solve my problem with it's help. Basically I need to layout some editable graphical UI elements (arrows, circles, text blocks, etc) on a grid. The layout is supposed to be nested - i.e. some grid cell may contain another grid of UI elements. The M/V framework seems to be exactly what I need - QAbstractiItemModel allows to define nested or recursive layout. I also created several item delegates which draw my geometric primitives and allow me to edit text blocks. Now I'm stuck with the front-end side of things. It looks like any of the existing implementations of QAbstractItemView does not support displaying nested models, so I looked for implementing QAbstractItemView.

There is no QAbstractItemView subclassing reference. Right now I'm trying to subclass it and display my nested model using the delegate classes I created, but it seems to be a complicated task.

What is necessary to implement such a view?

Thanks
Anton

P.S.
I searched the forums. This question seems to be pretty common, but I have not found an explanation or an example.

wysota
11th October 2008, 15:11
If you are after graphics, it might be easier to use QGraphicsView.

psih128
11th October 2008, 16:36
If you are after graphics, it might be easier to use QGraphicsView.

Yes, I'm after graphics, but interactive graphics, plus editable text. Basically I'm working on kind of a flow-chart editor. I believe it's quite complicated to implement it solely using QGraphicsView..

Edit:
Stupid question.. I should have checked QGraphicsView earlier! Probably I will go for it. Thanks!

But still my question about QAbstractModelView is open. How complicated is it to subclass it? I looked at the Chart example, but painting in the example is implemented directly in the View paintEvent, but I want to draw using delegates.

wysota
11th October 2008, 20:14
Yes, I'm after graphics, but interactive graphics, plus editable text.
That's another argument to use graphics view.


Basically I'm working on kind of a flow-chart editor. I believe it's quite complicated to implement it solely using QGraphicsView..
On the contrary :)


But still my question about QAbstractModelView is open. How complicated is it to subclass it? I looked at the Chart example, but painting in the example is implemented directly in the View paintEvent, but I want to draw using delegates.

Painting items using delegates is easy. The most complicated things are mapping between indexes and their positions on screen. Take a look at my custom view: http://www.wysota.eu.org/charts.html. It doesn't use delegates per se but a very similar concept.

aamer4yu
13th October 2008, 07:32
You can also have a look at the Diagram scene example under Graphics View in Qt Demos