Zooming scene Rect(Qt bug?)
Hi guys,
I have 2 problem connected with zooming the scene.
First of all, I am using the code beneath to zoom the given rect, but it alwas zoom the center(at the begining, for the first 2 times).
Code:
void MyCLass
::vZoomSceneRectangle(QRectF _rectangle
) {
m_view->fitInView(_rectangle,Qt::KeepAspectRatio); // or Qt::KeepAspectRatioBy expanding
m_view->ensureVisible(_rectangle);
}
The second problem is connected with fixed position. I have created QLabel as view->viewport() children(to set fixed position). When I scale the view(scale(2.0,20)), for the first 4 times their position is ok, but when I zoom In for the 5 time they change their position. So i am deleting them and recreating everytime they I zoom the scene rect and their position is ok(even though there are some painting lags).
But when I use fitInView(QRectF) method my QLabel position changes and I am back where my problems appeared.
Any idea how to zoom the chosen rectangle(correctly); I am currenly reading selected rectangle from the scene and use fitInView(QRectF..).
How to force my widgets to ignore zooming(I belive it should be a default action , when I created them as children of the view->viewport()).
For any ideas thank YOU.
Maverick
Re: Zooming scene Rect(Qt bug?)
How did you initialize the scene? Did you set the range of coordinates for it?
Re: Zooming scene Rect(Qt bug?)
I have implemented my own custom scene.
Here is the initialization.
Code:
m_scene = new GScene(this);
m_scene->setSceneRect(-50,50,m_view->width(),m_view->height());
m_scene
->setBackgroundBrush
(QBrush(Qt
::gray));
Maverick
Re: Zooming scene Rect(Qt bug?)
And how do you call the zooming method? A minimal compilable example reproducing the problem would help...
Re: Zooming scene Rect(Qt bug?)
I have a parent class which contain scene and view objects.
When I choose a rectangle for zooming I emit a signal which is connected to parent slot.
SIGNAL:
Code:
emit vSignalZoomRectangle(m_zoomPolygonItem->boundingRect());
//m_zoom PolygonItem is a QPolygonItem created in the scene coordinates(the rect for zooming)
SLOT:
Code:
void MyClass
::vZoomSceneRectangle(QRectF _rectangle
) {
m_view->fitInView(_rectangle,Qt::KeepAspectRatio);
//m_view->ensureVisible(_rectangle);
the connection is ok, and the correct rectF is passed, but no matter the rect coordinates the first zooming in ans other zoom the scene center point.
?
Re: Zooming scene Rect(Qt bug?)
What are the exact numbers of the scene size and the rect you pass to fitInView?
Re: Zooming scene Rect(Qt bug?)
It depend because I have a rectangle moving on the scene, and when I press the left mouse button the rectangle boundingRect is being read and passed.
I have checked again and the rectangle passed/received are the same and do change their position.
Maverick
Re: Zooming scene Rect(Qt bug?)
I'd like to see the numbers though... In my opinion, you create the scene with incorrect coordinates - you use the size of the view, but I suspect the view hasn't been shown earlier, thus it doesn't have its size calculated yet and you are receiving bogus values that later on cause your scene to be always centered in the view (which is a normal behaviour if the scene is smaller than the view). So please use qDebug() and inspect those values.
Re: Zooming scene Rect(Qt bug?)
Here are Top left/right and bottomLeft/Right points of the rectangles printed by the code in the Slot:
Code:
qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
1.
-606 -21
-356 -21
-606 -171
-356 -171
2.
340 -76
590 -76
340 -226
590 -226
3.
-135 99
115 99
-135 -51
115 -51
1. 2. and 3. are different coordinates, but after fittingInvView(rect..) I get the same zoom effect.
??
Re: Zooming scene Rect(Qt bug?)
Re: Zooming scene Rect(Qt bug?)
THe scene size is the same before zooming and after the action, but despite the given rectangle the scene looks the same after first zooming.
Maverick
Re: Zooming scene Rect(Qt bug?)
But what is the scene size? :) Could you show the exact figures - the scene size, the view size, the matrix of the view and the rectangle?
Something like (relative to the view object):
Code:
qDebug() << sceneRect() << size() << matrix() << _rectangle;
Re: Zooming scene Rect(Qt bug?)
maverick_pol, please just send a compilable self-contained example, and the bug is likely to be revealed right away. It's hard to debug code that's translated to english.
Re: Zooming scene Rect(Qt bug?)
Hi,
I can't send you the code as I do not have permision to do so. I will send the (rectangle/size/etc) within 15 minutes.
Here it is:
The code I am using to print values:
Code:
// the given _rectangle for zooming
qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
m_view->fitInView(_rectangle,Qt::KeepAspectRatio); // or Qt::KeepAspectRatioBy expanding
// Scene rectangle
_rectangle = m_view->sceneRect(); qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
// scene rectangle(from view)
_rectangle = m_scene->sceneRect(); qDebug()<<(_rectangle.bottomLeft().rx())<<(_rectangle.bottomLeft().ry());
qDebug()<<(_rectangle.bottomRight().rx())<<(_rectangle.bottomRight().ry());
qDebug()<<(_rectangle.topLeft().rx())<<(_rectangle.topLeft().ry());
qDebug()<<(_rectangle.topRight().rx())<<(_rectangle.topRight().ry());
// view size
qDebug()<<m_view->size().height()<<m_view->size().width();
//view matrix
qDebug()<<m_view->matrix().m11()<<m_view->matrix().m12()<<m_view->matrix().m21()<<m_view->matrix().m22()<<m_view->matrix().det()<<m_view->matrix().dx()<<m_view->matrix().dy();
HEre is the result:
-172 38
78 38
-172 -112
78 -112
-50 80
50 80
-50 50
50 50
-50 80
50 80
-50 50
50 50
660 1224
4.34667 0 0 4.34667 18.8935 0 0
QGraphicsScene::removeItem: item 01F45440's scene (00000000) is different from this scene (01AB88D8)
-51.3037 67.408
11.1963 67.408
-51.3037 29.908
11.1963 29.908
-50 80
50 80
-50 50
50 50
-50 80
50 80
-50 50
50 50
660 1224
17.3867 0 0 17.3867 302.296 0 0
QGraphicsScene::removeItem: item 01E9E968's scene (00000000) is different from this scene (01AB88D8)
-30.8857 57.2278
-15.2607 57.2278
-30.8857 47.8528
-15.2607 47.8528
-50 80
50 80
-50 50
50 50
-50 80
50 80
-50 50
50 50
660 1224
67.84 0 0 67.84 4602.27 0 0
QGraphicsScene::removeItem: item 01F78660's scene (00000000) is different from this scene (01AB88D8)
-19.487 52.5501
-15.5808 52.5501
-19.487 50.2064
-15.5808 50.2064
-50 80
50 80
-50 50
50 50
-50 80
50 80
-50 50
50 50
660 1224
271.36 0 0 271.36 73636.2 0 0
I have used zoom In 4 times here and after the second Zoom IN my widgets(created with m_view->viewport() as the parent) moved left. I tried to recreate the widgets after zooming In (removing items and addint them once again) that's why I get the "removeITem" warning.
Maverick
Re: Zooming scene Rect(Qt bug?)
Looks like I was right from the very beginning - scene coordinates seem incorrect.
BTW. You could have formatted the output better, you know...
Re: Zooming scene Rect(Qt bug?)
Hi,
I will format the INPUT correctly. Sound good that you were right, but I still do not know what is the problem. Could you explain it to me?
When I use (scale() and fitInView() ) function the coordinates system changes, what kind of incorrectness you're seeing here?
I really appreciate your help in this thread.
Maverick
Re: Zooming scene Rect(Qt bug?)
Take a look at the coordinates of the zooming rect, the scene and the view during first two zooms. If you have trouble, take a piece of paper and draw the rectangles, taking a closer look at how they intersect each other. Only during the last two sets of coordinates the zooming rectangle is smaller than the scene. A nice thing to have would be to know the bounding rect of all the items in the scene as well...
You should really try with a minimal compilable example as asked at the beginning... Or provide actual code - we won't steal it :)
1 Attachment(s)
Re: Zooming scene Rect(Qt bug?)
Hi,
Here is the piece of code I am using ( it's 100% what I have in my application(the part connected with gview framework).
After choosing the Zoom in from the Context menu and once again clicking left mouse button the rectangle appears and can be moved with the cursor and resized while pressing the right mouse button.
(There are 2 windows, the one with the gview is mine; other is not used)
My "Panels"(in the fungc class) should be at the same place while zooming, but are moving.
also in the begining(while zooming for first 2...4 times the center of the scene is zoomed not the rectangle).
If you have any ideas I would appreciate your help.
P.S. I have compiled/run this code using Qt 4.3.1 under win32
Maverick
Re: Zooming scene Rect(Qt bug?)
Hi guys,
Any ideas what can be the problem?(wrong zooming rectangle and moving Panels(labels))
Maverick
Looking for a solution for over a week...can't find it ;((GraphicsView)
Hi guys,
Excuse me for writing again about this problem, but the (my)last thread seems to die.
I have a problem, which I can't solve for over a week, I attach the code and the link to the thread. If anyone could at least compile the code at look where the problem may be and give some ideas I would really appreciate it.
THe problem.
http://www.qtcentre.org/forum/f-qt-p...-bug-8625.html
Thank you very much for your patience.
Maverick