PDA

View Full Version : Anybody knows a trick to cancel QGraphics painting ?



tonnot
6th December 2011, 09:55
I'd want to have (I need it... ) a method to cancel QGraphics view update - painting.
I dont find anything. Maybe I can be possible to do it using some qapplication cancel events ?
In addition, the drawitems is marked as obsolete (Is there some hidden substitute ? )
Any idea ? Thanks

stampede
6th December 2011, 12:55
Can you explain in what situation you need such thing ?

tonnot
6th December 2011, 13:50
Situations.... A lot, all of them when working with big vectorial worlds and big raster images.
Basically during the painting process I see what I'm going to see and I decide to do a new zoom, or pan or close the viewer.
(And I'm sure I can think on more ).
Thanks.

d_stranz
6th December 2011, 18:57
You know, tonnot, the more questions you ask, the more it sounds like you are going about designing your application completely the wrong way.

If you have to resort to all sorts of "outside the box" tricks to prevent Qt from doing what it was designed to do, then maybe you should question why your design seems to *require* all these tricks in order to have adequate performance. I gave you one piece of advice on how to avoid excessive repaints; you didn't like that idea, so you're still trying to find ways to defeat Qt.

Why? You'll likely end up with an application that completely breaks next time a new release of Qt comes out or if you have to change it to add some new feature, because you've had to write it in a way that doesn't conform to standard Qt expectations.

tonnot
7th December 2011, 14:48
Thanks D_stranz. I thank your advice about excesive repaints. It works. But I keep having a problem when zooming. I can catch up to 5 wheel events in 100 ms. and I can draw my world into a world coordinate system resulting of the 5th zoom. But I think that the user are going to experiment some kind of disconfort. (I experiment it).
The solution would be to draw '10 ms pieces' of my world. This would be more visually confortable. But to do this I'd need a way to cancel. Now I can only think to do something at item->paint level or calling sucesive 'invalidate_scene'.
I'm going to think on it ... again ....
Thanks

d_stranz
7th December 2011, 19:13
But I keep having a problem when zooming. I can catch up to 5 wheel events in 100 ms.

OK, the way I handle this kind of problem is to uncouple the wheel event from zooming. Instead of zooming when the wheel event occurs, set a timer instead that has a medium-short timeout (maybe 250 - 500 ms). If the user spins the wheel quickly, a new wheel event will occur before the timer fires, so in the wheel event you record the wheel movement, stop the timer if it is running, then start it again. Finally, when the user stops moving the wheel, the timer will fire, and *then* you zoom (in the timeout slot), using the total amount of wheel movement you have added up.

If there is 250 ms delay between the time the user stops the wheel and the update, it will not be noticeable to the user, since the redraw takes longer than that.

tonnot
7th December 2011, 21:35
Thanks d_stranz
When I finished my code I have the intention to share it here . Before doing it, can I send you to know your opinion ?
( I promise you that the code will be fully functional, that is, it does not going to be an ask).