PDA

View Full Version : QGraphicsView:: PaintEvent(event) function slow on Windows XP + QT 4.5.1



nileshsince1980
18th November 2009, 06:23
Hello All,

I have created application on Windows/Linux using QT 4.5.1 (Open Source). I have used QGraphicsView/Scene architecture to display Graphics items (rectangles etc).

I have implemented zoom selection functionaliy. i.e. on Mouse selection, the zoom in the selected area using QGraphicsView::fitInView() function.

My code works fine on Linux but on Windows XP it hangs/slows down after 2 consecutive zoom in operations.
Please tell me what could be the cause ?? Or any clue.

Following is the functions from my code,

void MyGraphicsView:: PaintEvent(QPaintEvent * event)
{
QPaintEvent *newEvent = new QPaintEvent(event->region().boundingRect());
QGraphicsView:: PaintEvent(event);
delete newEvent;
}

void MyGraphicsView::mouseReleaseEvent(QMouseEvent *event)
{
QPainterPath path = scene()->selectionArea();
scene()->clearSelection();
fitInView(path.boundingRect(), Qt::KeepAspectRatio);
QGraphicsView::mouseReleaseEvent(event);
}

Some observations :
1. I have notices that same code works fine on Windows for QT 4.3.1 but not with QT
4.5.1. I have also checked the updations/changes of in 4.5.1 version but not able to
find much info. But in 4.5.0, QGraphicsView::fitInView() function has been improved for
very small viewport. (see the link http://qt.nokia.com/developer/changes/changes-4.5.0

2. I have obersred after some debugging that QGraphicsView:: PaintEvent(event) function is taking too much time to paint the view after 2/3 consecutive zoom-in operations.

Can anybody tell me why QGraphicsView:: PaintEvent(event) function is taking too much time.

Thanks in advance.
Nilesh

scascio
18th November 2009, 08:32
I haven't the solution of your problem but I note 2 points :

What are you overloading the paintEvent for? The default might be sufficient, I think.
Defining a the zoomed rect from selected items is quite weird. If items are not selectable, you can't zoom in!

nileshsince1980
18th November 2009, 10:11
I haven't the solution of your problem but I note 2 points :

What are you overloading the paintEvent for? The default might be sufficient, I think.
Defining a the zoomed rect from selected items is quite weird. If items are not selectable, you can't zoom in!

thanks for reply...

What are you overloading the paintEvent for? The default might be sufficient, I think.
>> I have overloaded paintEvent(..) to increse the performance.

Defining a the zoomed rect from selected items is quite weird. If items are not selectable, you can't zoom in!

>> What do yuo mean by this ?? I didnt get you.All items are selectable in my application.

scascio
18th November 2009, 11:18
Appart the allocation and deallocation that consume time, are you sure you are creating an paintEvent with a smaller rect?
event->region().boundingRect() is not equal to event->rect() ? In that case, you are just copying the event, aren't you?

I mean that performing zoom might be independant from selected objects. You can manage a QRubberBand member updated with mousePressEvent, mousePressMove, and perform your zoom in mousePressRelease.

You may concentrate on how item are painted.
If you have custom items or pixmaps, zooming might be time consuming since they are scaled. You can overload the QGraphicsItem::paint method to save time.