Question

I have a QGraphicsObject with a custom paint() method, displayed in a window too small to show in its entirety. When I use the bottom scrollbar to scroll around, instead of drawing a rectangle like it should, paint.drawRect() draws a triangle.

It seems this only happens when I scroll all the way to the bottom left corner - no other corners are affected. If I maximize the window and restore it to the original size, then try it again, it works properly and no diagonal line shows up.

Screenshot

I've got some test code here. Press the + and - keys to zoom in and out, respectively.

I'm flummoxed. Is this a bug, or am I missing something here? What can I do to fix this?

I'm on PySide 1.2.1, Python 3.3.2, and Windows 8.

Was it helpful?

Solution

I've experienced the same running the Qt example "elastic nodes", which is one of the Graphics View examples. You can reproduce the diagonal line by zooming in (using '+' or the mouse wheel), until the frame rectangle is outside the visible area.

Workaround: deactivate the background cache (graphwidget.cpp, constructor, remove the line "setCacheMode(CacheBackground);"), compile, run => no diagonal line.

Btw, I'm using Qt 4.8.5.

I just had a look at the Qt bug tracker and found QTBUG-31579, where unexpected things are drawn when using a pen width of 0, so I tried modifying the elastic nodes example by drawing the rectangle with an explicit pen of 1 pt width, which gave me the expected result even with the background cache enabled. Since it seems they are working on that problem, it should be solved with the next Qt release.

Sorbet, if you need a solution more quickly, you could try to set an explicit pen of nonzero with when drawing.

Hope this works for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top