PDA

View Full Version : Flicking overlayed widget on a QGraphicsView with QLWidget



scascio
11th September 2009, 14:54
Hello,

Glad to have found this forum and to use these so powerful Qt environment

For my troubles working with QGraphicsView, I searched around several possibilities without success. So I post this thread and hope some help.

I use a QGraphicsView to manage a lot (about 100000) heavy multi resolution image items (about 2Go each).
So I derived QGraphicsItem to implement my own paint event according to the region refreshed and the level of details displayed. It works very well.

In addition, I implemented a tool, attached to the mouse, that is used to see a reducted area under the mouse pointer, at a different lod. Unfortunalty, I cannot grab the result of the paint since I need the real data a better resolution.

The idea I found was to create a floating QGraphicsView, which is populated at each mouse move with the usefull items. Since there ara copied into a new scene, the paint themself with the right region and the right lod. It works perfectly.
I had also tried to manage a top level item but moving it for each mouseMove horribly slows down perfomance.

Due to the heavy data to be displayed, I found that using a QGLWidget with double buffering activated as the viewport of my first QGraphicsview give me better perfomances, even when at high zoom factor.
How great and so easy to use :

setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

But my joy was slapped down when I noticed a strange flickering when my zoom cursor was displayed, at the upper left corner of the first view.

Without OpenGL activated, the mouse cursor are always good, but perfomance are not satisfying.

This is not only flickering because when I am editing a polygon on the QGraphicsView, whose shape it attached to the mouse, the current edited vertex is displayed on the corner of the screen, giving my polygon a strange distorsion!

After investigation, it seems that the mouseMove event, in which I set the position of the cursor widget and vertex, is triggered with bad coordinates, whose values are under (100,100).
This trouble happens for any QWidget overlayed over the QGraphicsView with QGLWidget set as viewport.

I read on this forum that my case is not supported by Qt team, but does anyone has encoutered this problem, or implemented a cursor zoom functionnality in another way?

Since I am using the version 4.5.0, am I right to hope better results with 4.6?

Thanks by advance

S.Cascio

scascio
16th September 2009, 11:23
Since I have found afterwards that hard to read, I will simplify :

Simply derived a QGraphicsView with some items in it.
Add a member QLabel, never mind if empty, as child widget
Overload the QGraphicsView::mouseMoveEvent to attach the child widget to the mouse position, with an offset of -size/2.
Then, set a QGLWidget viewport of your QGraphicsView, with

setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

When moving mouse, sometimes you can see the widget drawn on the upper left corner of the QGraphicsView, like a flickering or if it was drawn there before moving as kind of double buffering.

But if you trace the mouse positions, you will see that the coordinates have changed to this weird position, so the drawing is good.
This stuff does happen only with OpenGl activated.

S.Cascio