PDA

View Full Version : QGraphicsView inside of QAbstractItemView viewport



Paladin12
1st December 2009, 22:56
Hi all,

Given:



class MyView : public QAbstractItemView
{
...

private:
QGraphicsView *view_;
};


and:



MyView::MyView(...)
{
...
view_ = new QGraphicsView;
setViewport( view_ );
...
}


How can I get the viewport of QGraphicsView to match the viewport of MyView when resizing? As it always stays as a fixed size. How can I get it to stretch to to the whole MyView sreen space?

Kind Regards,

wysota
3rd December 2009, 13:58
What exactly do you mean by fixed size? I'm not sure if doing it this way is a good idea... It might be easier not to use graphics view at all, just use QGraphicsScene and QGraphicsScene::render() to render the contents of the scene on the already existing viewport.

Paladin12
3rd December 2009, 14:17
Hmm, yes, my explanation wasn't great. Apologies...

What happens is that the view derived from QAbstractItemView displays the QGraphicsView in the upper left corner of the viewport and it has a small fixed size. Resizing the viewport of the custom view does not change the geometry of the QGraphicsView.

What I'm trying to do is us the graphics framework on top of the standard Model-View classes to display and manipulate data graphically. So basically I would use the standard Model-View approach but use the graphics framework for display and input.

Any suggestions for alternative approaches are welcome.

wysota
3rd December 2009, 14:30
QAbstractItemView inherits QAbstractScrollArea and not QScrollArea thus the viewport is actually kind of virtual. It has the size smaller than the size of the view and scrollbars don't modify the offset of the viewport widget just tell the implementation that it has to shift the contents it draws on the fixed viewport.

I can imagine setting graphics view as the viewport for itemviews view but it will not work as you expect it. You won't be able to scroll it or anything. It will just be a static canvas you can draw on using QPainter only (meaning no graphic items). The only way I see to do what you want is to do what I already said - forget about graphics view and use only graphics scene and its render() member forwarding all calls from QAbstractItemView to the scene.

mxl
24th January 2016, 13:04
OK for the QPixmap alternative, thanks, but what if we need to interact with the QGraphicsview's QGraphicsitems ???

@Paladin12: Putting your QGraphicsview into a layout assigned to the QAbstractItemview viewport should solve your resize problem...

anda_skoa
24th January 2016, 14:15
Any specific feature of the QAbstractItemView base implementation that you need?
Do you need to pass it to some function that takes QAbstractItemView or implements algorithms on the base class?

Cheers,
_