PDA

View Full Version : QGraphicsWidget disappear when scrolling QGraphicsView



T4ng10r
18th January 2010, 13:13
I draw few objects and connections between them. All objects are subclassed from QGraphicsWidget.
If I scroll view so that part of grey rectangle is not visible - then all lines/connections are gone. Lines/Connections are set as children to those rectangles.
The same situation with lines between rectangles. There's one big QGraphicsWidget set as parent for them and used to expand view - this big widget is a parent for lines/connections between rectangles. And they disappear too.
For me it looks like some kind clipping.

That's how I paint rectangles (smaller one have different colour) .

QColor cGray(Qt::gray);
cGray = cGray.light();
QBrush brush(cGray);
painter->setBrush(brush);
painter->drawRect(0,0,size().width(),size().height());

And connections/lines.

QPen stPen;
stPen.setWidth(2);
painter->setPen(stPen);
painter->drawLines(m_vPathLines);

Params set for QGraphicsView

m_ptrSceneView = new QGraphicsView;
m_ptrSceneView->setInteractive(true);
m_ptrSceneView->setDragMode(QGraphicsView::ScrollHandDrag);
m_ptrSceneView->setScene(&m_RP3Scene);
m_ptrSceneView->setViewportUpdateMode(QGraphicsView::FullViewportU pdate);


http://www.img-share.net/thumbnail/66Sim_Screen3.JPG (http://www.img-share.net/uploads/66Sim_Screen3.JPG)
http://www.img-share.net/thumbnail/39Sim_Screen4.JPG (http://www.img-share.net/uploads/39Sim_Screen4.JPG)

Could some one tell me - how to set this Graphics Environment, so lines/connections won't disappear when I scroll?

axeljaeger
19th January 2010, 21:49
Try to start you application with a different graphicssystem and see whether it makes any difference. See the documenation of QApplication constructor for a list of possible values for graphicssystem.

T4ng10r
20th January 2010, 14:45
QApplication::setGraphicsSystem() can be set with 'native', 'raster' and 'opengl'. There's no difference between them - problem hasn't been solved. Only use of 'opengl' is different - it crashes app somewhere deep inside in QGLGlobalShareWidget during start-up event processing.

Thank you for suggestion, but my problem still exist.

axeljaeger
20th January 2010, 14:47
Does it make any difference when you remove the m_ptrSceneView->setViewportUpdateMode(QGraphicsView::FullViewportU pdate); ?

T4ng10r
21st January 2010, 09:05
Difference between update modes is only how much he redraws. FulllViewportUpdate redraws everything - and that why lines disappears after one scroll. With others update modes - it redraws only some small part of screen. And this part is without my lines.

This is screenshoot with SmartViewportUpdate update mode after three moves down and three up.
It looks like when I scroll down - it doesn't redraw lower part of lines. It leaves screen as it was, but in places revealed by scroll there's nothing. The same when I move scroll up - it draws empty space where lines should be. When I get to the top - it draws visible part of line, but rest isn't draw.
http://www.pl.image-share.com/upload/6/141m.jpg (http://www.pl.image-share.com/image.php?img=6/141.jpg)

The same here - with MinimalViewportUpdate update mode after scroll to the bottom of scene and back.
http://www.pl.image-share.com/upload/6/140m.jpg (http://www.pl.image-share.com/image.php?img=6/140.jpg)

axeljaeger
21st January 2010, 09:08
Can you create an about 100 lines example application that shows that bug so I can try out here?

T4ng10r
21st January 2010, 10:18
That's the simplest program. I even didn't have to implement connection objects to show result.
If you run it, make view smaller - to fit inside only one rectangle - and perform scroll down (with mouse or keys).
You'll see that part of rectangle which wasn't visible isn't redraw (small circles aren't draw entirely) .

http://www.nopaste.pl/Source/l5k.txt

EDIT:
And in this one I've added connections. Like above - this time ALL small circles (CRectSmall) are drawn, but only 2 or 3 of connections for each rectangle is being draw.

http://www.nopaste.pl/Source/l5n.txt

faldzip
21st January 2010, 12:04
But why are you using QGraphicsWidget's for such things, like drawing circles? Can't you use QGraphicsItem subclasses with properly implemented boundingRect() (and optionally shape()) and paint() ?

T4ng10r
21st January 2010, 12:16
With reimplementing boundingRect I had lots of problems. Mainly positioning inside parents and on scene. In other situation I needed info about position of others scene object - but they weren't set till final object placement. QGraphicsWidget gave me ability to set size and pos and used them in other places without waiting for final scene placement where position and size are stored.

faldzip
21st January 2010, 12:36
With reimplementing boundingRect I had lots of problems.
You didn't spend enough time on reading docs and analyzing given examples. Bounding rectangle is in item's coordinates so if you have rectangle item 20x20 then bounding rectangle returned by boundingRect() should QRectF(0,0,20,20).
Then drawing in paint() is also done in item's coordinates so doing like this:


painter->drawEllipse(pos().x(), pos().y(), 20, 20);

will cause painting outside the item's bounding rect, which effects you can see in your app. The proper code would be:


painter->drawEllipse(0, 0, 20, 20);

assuming that bounding rect is at least with w=20, h=20;


Mainly positioning inside parents and on scene. In other situation I needed info about position of others scene object - but they weren't set till final object placement. QGraphicsWidget gave me ability to set size and pos and used them in other places without waiting for final scene placement where position and size are stored.
It is rather logical for me that item has no position if it is not added to any scene yet (or any parent) because there is no valid position. And notice that pos() is in parent's coordinates and scenePos() in scene's.

T4ng10r
21st January 2010, 13:24
When I changed base class for Connection from QGraphicsWidget to QGraphicsPathItem - it solved my problem. I didn't even have to change or reimplement boudingRect() - it's done automatically.