Results 1 to 19 of 19

Thread: Problem in MouseMoveEvent

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Problem in MouseMoveEvent

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class MainWindow : public QMainWindow
    4. {
    5. public:
    6. MainWindow(QWidget* parent = 0) : QMainWindow(parent)
    7. {
    8. QGraphicsItem* item = scene->addText("Item");
    9. item->setFlag(QGraphicsItem::ItemIsMovable);
    10.  
    11. view = new QGraphicsView(scene);
    12. view->viewport()->installEventFilter(this);
    13. // this is not actually even needed, QGraphicsView
    14. // already sets the mouse tracking on on it's viewport
    15. view->viewport()->setMouseTracking(true);
    16. setCentralWidget(view);
    17. }
    18.  
    19. bool eventFilter(QObject* object, QEvent* event)
    20. {
    21. if (event->type() == QEvent::MouseMove)
    22. {
    23. QMouseEvent* mouse = static_cast<QMouseEvent*>(event);
    24. QPointF pos = view->mapToScene(mouse->pos());
    25. statusBar()->showMessage(QString("(%1,%2)").arg(pos.x()).arg(pos.y()));
    26. }
    27. return false;
    28. }
    29.  
    30. private:
    31. };
    32.  
    33. int main(int argc, char* argv[])
    34. {
    35. QApplication app(argc, argv);
    36. MainWindow w;
    37. w.show();
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 8th November 2006 at 08:47.
    J-P Nurmi

  2. The following user says thank you to jpn for this useful post:

    aamer4yu (8th November 2006)

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.