[Qt-interest] Custom cursors, OpenGL and update problems

Oliver Demetz forenbeitraege at oliverdemetz.de
Thu May 21 13:16:04 CEST 2009


Hi!

I am using something which is not officially supported but I hope you 
can still give me some help.

I am working thit a QGraphicsView and Scene. The view's viewport is a 
QGLWidget.

       QGraphicsView view(&scene, this);
       QGLWidget * m_view_viewport = new
             GLWidget(QGLFormat(QGL::SampleBuffers | QGL::Rgba));
       m_view.setViewport(m_view_viewport);

Ok, for the items in the scene, I need a special round cursor with 
*large diameters*, eg. 150 pixels. They are created as follows:

       int m_toolsize = 150;
       //get power of two
       int cs = 2;
       while(cs<m_toolsize) cs *= 2;

       QBitmap bm(cs,cs);
       QRect r (0,0,cs,cs);
       QRect toolrect ( qRound(0.5*(cs-m_toolsize)),
                        qRound(0.5*(cs-m_toolsize)),
                        m_toolsize, m_toolsize);
       QPainter painter;
       painter.begin(&bm);
       painter.fillRect(r, QBrush(Qt::color0));
       painter.setPen(QPen(QBrush(Qt::color1), 2));
       painter.drawEllipse(toolrect);
       painter.end();
       item->setCursor(QCursor(bm,bm));

This creates a round circle shaped cursor with diameter 150 pixels, 
which is transparent in the middle. Nice for far.

But, I was already mentioning the OpenGl stuff:
The paint method of my item *directly* uses openGL calls to paint  its 
contents. This is possible since the viewport widget is an opengl widget.

The *problem* now is that this cursor is used as a tool to alter the 
appearance of my item. This work fine if I use the standard cursor. But 
as soon as I use my custom cursor, the update of the area under the 
cursor of the item fails and the original appearance (must be cached) of 
my item before the tool was applied is shown again.
One can also see some flickering.

Also an fact I dont understand is that the custom cursor disappears if 
the mouse is not moved but the mousebutton is pressed. This is not the 
case for the standard cursor.

Note that this problem only appears with larger curor sizes (above 64x64).

Is this just a known issue that is cause by the underlying window 
system, or is it (solvable) bug?

Thanks in advance,
Oliver




More information about the Qt-interest-old mailing list