PDA

View Full Version : QGraphicsView::resizeEvent(event)



Mrdata
21st June 2011, 12:20
while looking at some examples to fix a problem i've related with correct resizing of qgraphicscene inside a qgraphicsview i noticed this is commonly used by other people but when i use QGraphicsView::resizeEvent(event); inside my application i always get this error during compilation:



void Myclass::resizeEvent( QResizeEvent *event )
{
QGraphicsView::resizeEvent(event);
......
}


error C2248: 'QGraphicsView::resizeEvent' : cannot access protected member declared in class 'QGraphicsView'

Rachol
21st June 2011, 12:25
Is Myclass a subclass of QGraphicsView?

Mrdata
21st June 2011, 13:06
No it isn't

Also, same error if i do like this:



void Myclass::resizeEvent( QResizeEvent *event )
{
myview->resizeEvent(event);
......
}

Rachol
21st June 2011, 13:09
Well, this is quite basic subject. You can't call a protected member from another class, unless it is a friend class or a subclass.

Edit:

So, you can do couple of things, for example:
* subclass QGraphicsView and implement resizeEvent method
* install eventFilter on QGraphicsView object and wait for event->type() == QEvent::Resize

in both cases you can just call setSceneRect(QRectF) on your QGraphicsScene object

Mrdata
21st June 2011, 18:26
i subclassed QGraphicsView and implemented resizeEvent, it works fine now :) Thanks