Results 1 to 9 of 9

Thread: QGraphicsScene doesn't enter drag event

  1. #1
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QGraphicsScene doesn't enter drag event

    Qt 4.3.2, MS VS 2005+integration
    I derived my MyGraphicsScene from QGraphicsScene and reimplemented:
    Qt Code:
    1. void MyGraphicsScene::dragEnterEvent(QGraphicsSceneDragDropEvent* event)
    2. {
    3. QApplication::setOverrideCursor(Qt::ClosedHandCursor);
    4. QGraphicsScene::dragEnterEvent(event);
    5. }
    6. void MyGraphicsScene::dragLeaveEvent(QGraphicsSceneDragDropEvent* event)
    7. {
    8. QApplication::restoreOverrideCursor();
    9. QGraphicsScene::dragLeaveEvent(event);
    10. }
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsScene doesn't enter drag event

    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.

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene doesn't enter drag event

    QGraphicsScene drag enter event? you can grab direct from QGraphicsitem
    on bool TextLayer::sceneEvent(QEvent *event)


    Qt Code:
    1. /* TextLayer like QGraphicsTextItem */
    2. bool TextLayer::sceneEvent(QEvent *event)
    3. {
    4. /* drag here */
    5. if ( event->type() == QEvent::GraphicsSceneDrop) {
    6. mount->txtControl()->processevent(event);
    7. return true;
    8. } else if (event->type() == QEvent::GraphicsSceneDragMove ) {
    9. /* QGraphicsSceneDragDropEvent *e = static_cast<QGraphicsSceneDragDropEvent *>(event); */
    10.  
    11. } else if (event->type() == QEvent::DragEnter ) {
    12. /*
    13.  
    14.  
    15. */
    16. }
    17. return QGraphicsItem::sceneEvent(event);
    18. }
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene doesn't enter drag event

    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.

  5. #5
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene doesn't enter drag event

    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

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsScene doesn't enter drag event

    Quote Originally Posted by Radagast View Post
    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...

  7. #7
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene doesn't enter drag event

    Quote Originally Posted by Radagast View Post
    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. 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?

  8. #8
    Join Date
    Jun 2008
    Posts
    57
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QGraphicsScene doesn't enter drag event

    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!

  9. #9
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsScene doesn't enter drag event

    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
    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.

Similar Threads

  1. Enter event mouse position
    By bunjee in forum Qt Programming
    Replies: 9
    Last Post: 7th May 2008, 19:53
  2. QItemDelegate enter event
    By bunjee in forum Qt Programming
    Replies: 6
    Last Post: 4th May 2008, 20:56
  3. Widget enter event
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 20th April 2008, 23:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.