Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 6

Qt-interest Archive, June 2007
Speed, transparency, and drop issues with QGraphicsView


Message 1 in thread

I've been running into speed issues with QGraphicsView attempting to  
do various operations.  I was under the impression that all in-window  
drawing should be extremely fast, but that doesn't seem to be the  
case.  What I want to do seems rather simple, but always ends up slow.  
  I'm putting the genesis of my code below with appropriate questions  
sprinkled throughout.

Original idea:

I have a main window that currently has a QGraphicsView located in the  
middle.  When a certain event happens, I want to have another  
QGraphicsView pop up with icons on it, semi-transparent over the  
original (so the original seems to "darken").  These icons animate as  
they pop up, by resizing.

So originally, I set the background:

     setBackgroundRole( QPalette::Base );
     QPalette p = palette();
     p.setColor( QPalette::Base, QColor(0, 0, 0, 0) );
     setPalette( p );
     setAutoFillBackground( true );

And I then had a QTimeLine that would cause the alpha value to change.  
  So when the timer fired:

     QPalette p = palette();
     p.setColor( QPalette::Base, QColor(0, 0, 0, value*4) );
     setPalette( p );

But this was extremely slow.  It also caused a "flash" when the QGV  
was shown or hidden (using show() or hide()) where the entire thing  
would flash white before drawing.  So I tried simply setting it to a  
final transparency value from the beginning, without using the  
QTimeLine to change it.  This was better but still very slow.

Question #1:  Was I doing something wrong here?  Can I expect to get  
decent partial-transparency speed somehow?

So at this point I decided to just use full transparency, which worked  
much more quickly.  But still the "flash" persisted.  Eventually I  
found out that I could start the "flash" on QGV's show by removing

    setAutoFillBackground( true );

from the initial code segment above.  Now, the items just seem to "pop  
up" on top of the QGV underneath.  But when I hide() the QGV, it still  
does this "flash" and I've not found a way to get around it.

Question #2:  What causes this "flash" and how can I stop it from  
happening on hide() (and on show() in case I want to have it fill the  
background)?

One thing I noticed at this point is that the QGraphicsView won't  
accept drops, despite

     setAcceptDrops( true );

in my constructor.  But the QGraphicsItems I add to my scene, which  
also have this set in their constructors, receive drops just fine.

Question #3:  Why isn't the QGV accepting drops?

So at this point I have a transparent QGV with some items derived from  
QGraphicsSvgItem.  They all share a QSvgRenderer so that I only have  
to read the SVG file once.  At the moment, they are all the same item,  
so they all render the same graphic.  I set up a QTimeLine to have  
these items resize so that they appear to grow in from nothing.  But  
as my QGV gets larger, say, if my main window becomes bigger, this  
becomes extremely slow, and I'm not sure why (unless the answer is  
"because they're SVGs").  I want to use SVGs because I want the size  
of the item to change (and look decent) depending on the size of the  
QGV.

Question #4:  Why is this resizing so slow, why is it affected by the  
QGV size, and can I do anything about it?

I think that's it for now.  Thanks in advance.

--
 [ signature omitted ]