View Full Version : RubberBand Problem
zgulser
11th February 2009, 11:45
Hi
I implement QRubberband respectively in the mousePress, mouseMove and mouseRelease methods of QGraphicsScene. But when I do the following I get a runtime error.
void myScene::mouseMoveEvent(QGraphicsMouseMoveEvent* event)
{
myRubberband.setGeometry(QRect(p2, event->screePos()));
QGraphicsScene::mouseMoveEvent(event);
}
The runtime error is : "Do not delete object 'unnamed' during its event handler"
What's wrong with it?
zgulser
11th February 2009, 12:36
I solved the problem, but new one arises:)
void AhwcsEcdisScene::mousePressEvent(QGraphicsSceneMou seEvent * mouseEvent)
{
p2 = mouseEvent->screenPos();
if(!mRubberband)
{
mRubberband = new QRubberBand(QRubberBand::Rectangle);
pressedFlag = TRUE;
}
mRubberband->setGeometry(QRect(p2,QSize()));
mRubberband->show();
isReleased = FALSE;
cout<<"Mouse PRESSED!!"<<endl;
QGraphicsScene::mousePressEvent(mouseEvent);
}
void AhwcsEcdisScene::mouseMoveEvent(QGraphicsSceneMous eEvent * mouseEvent)
{
if(pressedFlag && !isReleased)
mRubberband->setGeometry(QRect(p2,mouseEvent->screenPos()));
cout<<"Mouse MOVED!!"<<endl;
QGraphicsScene::mouseMoveEvent(mouseEvent);
}
void AhwcsEcdisScene::mouseReleaseEvent(QGraphicsSceneM ouseEvent * mouseEvent)
{
if(!mRubberband)
{
cout<<"Mouse RELEASED!!"<<endl;
mRubberband->hide;
isReleased = TRUE;
}
pressedFlag = FALSE;
QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
Mouse is not released! Any ideas?
zgulser
11th February 2009, 14:05
I done with the problem.
By the way is there any way to find items(if any) inside the rectangle returned by QRubberBand.rect()?
aamer4yu
11th February 2009, 16:55
Have a look at QGraphicsScene::selectedItems
zgulser
11th February 2009, 16:59
Does this method percepts rubberband or something different?
zgulser
12th February 2009, 09:13
Hi,
Can we use QRubberband to select QGraphicsItem from the screen? If yes, then how?
Regards.
talk2amulya
12th February 2009, 09:20
u can find the rect of ur graphic items and check if the qrubberband's rect contains the rect of graphic items..that should work
zgulser
12th February 2009, 09:29
Hi
ı already tried it, but there is type mismatching between QRect and QRectF:(.
talk2amulya
12th February 2009, 09:42
well, u can convert a QRect to QRectF or vice versa:
QRect QRectF::toRect () const
Returns a QRect based on the values of this rectangle. Note that the coordinates in the returned rectangle are rounded to the nearest integer.
QRectF QVariant::toRectF () const
Returns the variant as a QRectF if the variant has type() Rect or RectF; otherwise returns an invalid QRectF.
zgulser
12th February 2009, 09:44
Ok, I'am trying now. I will report back to you as soos as possible.
Thanks.
zgulser
16th February 2009, 07:05
Sorry for the late answer.
If I do QRubberband::setGeometry(QRect ...), then I couldn't handle the correct rubberband rectangle in order to include QGraphicsItem.
I used rubberband->rect().
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.