PDA

View Full Version : QGraphicsScene/QGraphicsView window limitations



mistertoony
14th February 2007, 20:11
i am an undergraduate student working with Qt. i've used QPolygonF to create polygons that have been attached to a scene as pathitems. using the following code for attaching points:

polygonC << QPointF(x,y);

x values range from 0 to 5000 and y values range from 0 to 150.

after successfully plotting the data, i have noticed that the majority of the data has not been plotted. examine the screenshot below.

http://www2.bc.edu/~nguyenah/sct_plot2.JPG

jacek
15th February 2007, 00:25
What is the size of your QGraphicsScene?

mistertoony
15th February 2007, 16:46
i initialized QGraphicsScene without parameters, for example, QGraphicsScene myScene.

jacek
15th February 2007, 17:08
What does polygonC.boundingRect() return?

mistertoony
15th February 2007, 18:27
whats the best way to display the information returned from polygonC.boundingRect()? through QMessageBox?

EDIT: i was unable to figure out how to display the information returned from .boundingRect(), however i set:

QGraphicsScene *scene = new QGraphicsScene(0,0,50000,0);

i noticed that the all four curves are cut off. is there a limitation on QPolygonF?

jacek
15th February 2007, 18:46
whats the best way to display the information returned from polygonC.boundingRect()? through QMessageBox?
qDebug() should be the quickest one.

mistertoony
15th February 2007, 18:50
jacek, polygons are cut off. im wondering if there is a maximum number of points a polygon may have.

Bitto
15th February 2007, 19:52
You might have run into a bug that was recently fixed; try applying this patch and see if it helps...



--- qgraphicsview.cpp 2007/02/05 13:30:58.000000000
+++ qgraphicsview.cpp 2007/02/12 16:26:20.000000000

@@ -338,6 +338,14 @@
int height = maxSize.height();
QRectF viewRect = matrix.mapRect(q->sceneRect());

+ // Adjust the maximum width and height of the viewport based on the width
+ // of visible scrollbars.
+ int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q);
+ if (viewRect.width() >= maxSize.width())
+ height -= scrollBarExtent;
+ if (viewRect.height() >= maxSize.height())
+ width -= scrollBarExtent;
+
// Setting the ranges of these scroll bars can/will cause the values to
// change, and scrollContentsBy() will be called correspondingly. This
// will reset the last center point.

rajesh
16th February 2007, 07:22
First you initialize QGraphicsScene without parameters, for example,
QGraphicsScene myScene.

later you calculate rect area(width & height) after drawing all items, then set following

scene->setSceneRect(0, 0, width,height);

(width = width of longest QGrapicsItem)


This will set scroll bar automatically. No need to set yourself.

mistertoony
16th February 2007, 18:06
First you initialize QGraphicsScene without parameters, for example,
QGraphicsScene myScene.

later you calculate rect area(width & height) after drawing all items, then set following

scene->setSceneRect(0, 0, width,height);

(width = width of longest QGrapicsItem)


This will set scroll bar automatically. No need to set yourself.

how do i calculate the rect area? i believe the problem is that polygons are unfinished, i manually extended the width of the scene and the polygons appear cut off.

http://www2.bc.edu/~nguyenah/scf_plot3.JPG

mistertoony
16th February 2007, 18:15
You might have run into a bug that was recently fixed; try applying this patch and see if it helps...



--- qgraphicsview.cpp 2007/02/05 13:30:58.000000000
+++ qgraphicsview.cpp 2007/02/12 16:26:20.000000000

@@ -338,6 +338,14 @@
int height = maxSize.height();
QRectF viewRect = matrix.mapRect(q->sceneRect());

+ // Adjust the maximum width and height of the viewport based on the width
+ // of visible scrollbars.
+ int scrollBarExtent = q->style()->pixelMetric(QStyle::PM_ScrollBarExtent, 0, q);
+ if (viewRect.width() >= maxSize.width())
+ height -= scrollBarExtent;
+ if (viewRect.height() >= maxSize.height())
+ width -= scrollBarExtent;
+
// Setting the ranges of these scroll bars can/will cause the values to
// change, and scrollContentsBy() will be called correspondingly. This
// will reset the last center point.


i can't find this cpp file on my system.

Bitto
17th February 2007, 09:10
The patch is against Qt's source code; you can download the sources, apply the patch, and compile/install the library, or wait for an official upgrade (this patch is part of 4.3).