PDA

View Full Version : QGraphicsScene selectedItems bounding rect returns -nan



devdon
30th September 2011, 21:34
QList<QGraphicsItem*> iList;

iList = scene->selectedItems();
QRectF bRect = scene->selectionArea().boundingRect();


Hello: The above code returns
h (qreal)
w (qreal)
x -nan(0xffffe1518ee2)
y (qreal)

Since I am new to QT perhaps this is to be expected, but the selectedItems() function seems a bit sketchy. I have an important routine that relies on it and it doesn't seem to return all the items consistently. Has anyone an explanation or similar experiences?

wysota
1st October 2011, 08:36
If selectionArea() returns an invalid path then its bounding rect will also be invalid. Did you call setSelectionArea() prior to executing this call?

devdon
1st October 2011, 09:11
I did not call setSelection area. Trying that does give a good bounding rect. I used the rubberband selection mode using the mouse and thought that would do the job alone. but in my quick trial based on your help I took the path of the rubberband selected area and set that as the path then called setselectionarea. My way seems redundant. Is there a more elegant way to do this? Thank you for responding.