PDA

View Full Version : QGraphicsScene doesn't enter drag event



Radagast
15th June 2008, 22:11
Qt 4.3.2, MS VS 2005+integration
I derived my MyGraphicsScene from QGraphicsScene and reimplemented:

void MyGraphicsScene::dragEnterEvent(QGraphicsSceneDrag DropEvent* event)
{
QApplication::setOverrideCursor(Qt::ClosedHandCurs or);
QGraphicsScene::dragEnterEvent(event);
}
void MyGraphicsScene::dragLeaveEvent(QGraphicsSceneDrag DropEvent* event)
{
QApplication::restoreOverrideCursor();
QGraphicsScene::dragLeaveEvent(event);
}
also my QGraphicsView has DragMode RubberBandDrag enabled.
But while dragging the mouse cursor doesn't changes :( the dragging itself runs OK.
then I put breakpoints into both functions and realized that the application even doesn't enters them.
I searched this forum and google but didn't find an answer...
Thanks in advance

wysota
15th June 2008, 23:27
RubberBandDrag has nothing to do with drag and drop. It's a flag that says that when you press and drag the mouse, items should get selected.

patrik08
16th June 2008, 12:07
QGraphicsScene drag enter event? you can grab direct from QGraphicsitem
on bool TextLayer::sceneEvent(QEvent *event)




/* TextLayer like QGraphicsTextItem */
bool TextLayer::sceneEvent(QEvent *event)
{
/* drag here */
if ( event->type() == QEvent::GraphicsSceneDrop) {
mount->txtControl()->processevent(event);
return true;
} else if (event->type() == QEvent::GraphicsSceneDragMove ) {
/* QGraphicsSceneDragDropEvent *e = static_cast<QGraphicsSceneDragDropEvent *>(event); */

} else if (event->type() == QEvent::DragEnter ) {
/*


*/
}
return QGraphicsItem::sceneEvent(event);
}



source on:
http://www.qt-apps.org/content/show.php/GraphicsViewEdit+Layer?content=80234

Radagast
16th June 2008, 13:12
I didn't subclassed any of QGraphicsitem..I don't need it) I just want to intercept the event on the Scene layer and change mouse cursor.

Radagast
16th June 2008, 13:12
I didn't subclassed any of QGraphicsItem..I don't need it) I just wonder why the Scene acts not like it's described in the assistant :(

wysota
16th June 2008, 15:37
I just wonder why the Scene acts not like it's described in the assistant :(

At which point? For me it behaves exactly as described in Assistant...

spud
16th June 2008, 17:43
I didn't subclassed any of QGraphicsitem..I don't need it) I just want to intercept the event on the Scene layer and change mouse cursor.
dragEnterEvent and dragLeaveEvent are for Drag and Drop (http://doc.trolltech.com/4.4/dnd.html). You seem to be wanting normal mouse move events.

You can set the cursor for a QGraphicsView by calling QWidget::setCursor(), or for a QGraphicsItem with QGraphicsItem::setCursor(). Does that solve your problem?

Radagast
16th June 2008, 18:01
Excuse me, I didn't write the problem neatly... I meant "Drag and Drop" operations for items in the scene, as it's already implemented by Trolltech. You just need to set QGraphicsItem::ItemIsSelectable|QGraphicsItem::Ite mIsMovable and that's all, you can easily drag'n'drop one or many items at the scene. And I was sure that in the moment of start dragging item(s), QGraphicsScene::dragEnterEvent receives control and in that moment I wanna change the mouse cursor. And when the user drops item(s), I restore the cursor. Is it possible to implement without subclassing QGraphicsItem?
and the 2nd tiny question...also I need to mirror an item relative to a line (to create a simmetric copy of the item). What is the easiest way to implement that? I know, that the solution lies somewhere near item's QTransform, but yet I can't see a universal way :(
thanks in advance for all your help!

spud
16th June 2008, 18:21
OK, I think I know what you mean now. I don't think what you want is possible without subclassing QGraphicsItem because of the way the Graphics View Framework handles mouse events (http://doc.trolltech.com/4.4/qgraphicsscene.html#event-handling-and-propagation)
All mouse events are delivered to the current mouse grabber item. An item becomes the scene's mouse grabber if it accepts mouse events (see QGraphicsItem::acceptedMouseButtons()) and it receives a mouse press. It stays the mouse grabber until it receives a mouse release when no other mouse buttons are pressed.