PDA

View Full Version : missing image with zoom (QGraphicsView)



avis_phoenix
16th March 2009, 19:45
Hi, everybody :p

I have a problem with the zoom in the qgraphicsview, in my scene I have a square with a grid, when I scale the scene to view this square, but the qgraphicsview clear some areas of the image...

I attach the code and put to image to show this error.

P.D.I try use FullViewportUpdate

http://www.geocities.com/platinium2000mx/ventana.jpg

With Zoom:
http://www.geocities.com/platinium2000mx/error.jpg

lni
16th March 2009, 22:19
too much code for a simple grid item...

But your CuadMesh::boundingRect has negative height causing exposure not being caught, change it to:



QRectF CuadMesh::boundingRect() const
{
return QRectF( QPointF( -1, -101 ), QSizeF( 101, 101 ) );
}

avis_phoenix
16th March 2009, 22:26
How can I improve my code?? Thanks a lot

wysota
17th March 2009, 00:34
But your CuadMesh::boundingRect has negative height causing exposure not being caught
There is nothing wrong with negative height of the rectangle. You're just reversing the coordinate axis to point upwards instead of downwards. Of course one needs to know what (s)he is doing to use it, I don't know if that's the case here, but the bounding rect is fine.

avis_phoenix: You don't need all those delete statements in the destructor. Read about memory management in Qt.

lni
17th March 2009, 15:08
There is nothing wrong with negative height of the rectangle.

You lost me, what does a rectangle with a negative height look like? Can you give an example that works in QGraphicsItem with negative height in its boundingRect? Also, you said his boundingRect is fine, then how do u fix his problem?

aamer4yu
17th March 2009, 18:07
I havent seen the code, but for improving it, you might try drawing the grid in drawBackGround function of view/scene ..

wysota
18th March 2009, 09:42
You lost me, what does a rectangle with a negative height look like?
It's Y axis points upwards not downwards probably, as already written, by the way...

lni
18th March 2009, 14:09
How can I improve my code?? Thanks a lot

Let me try to see if I can provide some "peer review" feedback. But people may have different opinion though..

If someone feels he has to spend more than 10 seconds to understand your code, he would most likely to turn away quickly. That is why those who answer your post doesn't really provide a real fix other than making some general comments, not because they don't know how to fix it. I look at your codes, and the only part I spent time on is CuadMesh::boundingRect, becasue it is only 1 line of code.

The use of QPainterPath along with so many moveTo and lineTo in the constructor is really difficult to understand. Try not to write too many things in constructor becasue of C++'s metamorphism...

I think you will not add other objects in CuadMesh class, right? If so, the codes would become even more unreadable and unusable in other places. If you add a banana in it, then I can't use it if I want to plot a cat with same grid. With that, I suggest to rename your class to CuadGridItem2D to be explicit, because when I unzip your codes, the first thing I did was looking for a *.h file with either "grid" or "item" in the file name, I didn't find it, so I have to open all the *.h files..

I add "2D' because you mix X-grid and Y-grid in the same class. What if I want X grid to be logarithmic and Y grid to be linear? What if I only want to have X grid and not Y grid? So, I would split it into CuadXGridItem and CuadYGridItem, and make a base class CuadGridItem. I am sure you are going to write more C++, with that, you can reuse the codes in many different projects on different requirements.

On CuadGridItem, you implement paint method by setting up pen and color, etc, and make a pure virtual "drawGridLine", and let XGrid and YGrid to implement how to draw, where XGrid draws in X direction, and YGrid draws in Y direction...

OO design is like marriage. In Houston where I live as well as in most other places, it works great to have a Marriage class where you define a marriage to be between a male and a female, but this class doesn't work in California...