PDA

View Full Version : RubberBandDrag, mouseMoveEvent and setSelectionArea



jonks
12th May 2009, 21:08
Hi,

I need advice - I have 2 problems I cannot solve :(

I'm using QT4.5.1

Firstly the mouseMoveEvent is not fired when drag mode is RubberBandDrag. Is this expected behavior?
Secondly when setSelectionArea is called, the setSelected function of my QGraphicsItem is not called.

Anyone have any ideas what i am doing wrong??
(have I forgotten to set any flags in my scene/graphicsitems?)
Code is below...

Thanks for any advice




// MyScene is derived from QGraphicsScene

void MyScene::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
views()[0]->setDragMode(QGraphicsView::RubberBandDrag);
m_rubberbandP1 = event->scenePos().toPoint();

QGraphicsScene::mousePressEvent(event);
}

void MyScene::mouseMoveEvent ( QGraphicsSceneMouseEvent * event )
{
if (views()[0]->dragMode() == QGraphicsView::RubberBandDrag)
qDebug() << "mouseMoveEvent"; // never displays
QGraphicsScene::mouseMoveEvent(event);
}

void MyScene::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{
views()[0]->setDragMode(QGraphicsView::ScrollHandDrag);

QRect rect(m_rubberbandP1, event->scenePos().toPoint());
QPainterPath pp;
pp.addRect(rect);
setSelectionArea(pp);
QGraphicsScene::mouseReleaseEvent(event);
}

aamer4yu
13th May 2009, 05:43
I am not able to guess what you are trying to achieve.
If selecting items is your aim, you better have a look at the 40000 Chips demo example in Qt Demos.

They have rubberbanding implemented there. It might help you.

jonks
13th May 2009, 06:29
Thanks for the pointer to the example.

I know what I was doing wrong now.

1. I should have been overriding dragMoveEvent, not mouseMoveEvent
2. I didn't set the ItemIsSelectable flag in the QGraphicsItem