Results 1 to 20 of 28

Thread: Mouse Press/Release Events

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Mouse Press/Release Events

    Dear All,

    Im getting mouseevent at when i click the mouse on the GraphicsScene. Im getting the position/co-ordinate also, where as release event im getting the co-ordinate/positions. please Suggest me
    Qt Code:
    1. #ifndef APP_H
    2. #define APP_H
    3.  
    4. #include <QMainWindow>
    5. #include <QGraphicsScene>
    6. #include <QPoint>
    7. #include <QMouseEvent>
    8.  
    9. protected:
    10. void changeEvent(QEvent *e)
    11. void mousePressEvent (QMouseEvent *e)
    12. void mouseReleaseEvent (QMouseEvent *e)
    13.  
    14. private:
    15. int x,x1,y,y1;
    16. QPoint *point;
    17.  
    18. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "app.h"
    2. #include "ui_app.h"
    3.  
    4. APP::APP(QWidget *parent):
    5.  
    6. QMainWindow(parent),
    7. ui(new Ui::APP)
    8. {
    9. ui->setupUi (this);
    10. }
    11.  
    12. void APP::mousePressEvent(QMouseEvent *e)
    13. {
    14. QPoint point=e->pos();
    15. x=point.x();
    16. qDebug()<<x;
    17.  
    18. y=point.y();
    19. qDebug()<<y
    20.  
    21. }
    22.  
    23. void APP::mouseReleaseEvent(QMouseEvent *e)
    24. {
    25. QPoint point=e->pos();
    26. x1=point.x();
    27. qDebug()<<x1;
    28.  
    29. y1=point.y();
    30. qDebug()<<y1;
    31.  
    32. }
    To copy to clipboard, switch view to plain text mode 


    Im getting x,y position data of Graphic scene when i click on scene, but not x1, y1 positions when i release mouse. By getting all co-ordinates i can draw line.
    Last edited by Vivek1982; 22nd July 2014 at 07:50.

Similar Threads

  1. Replies: 3
    Last Post: 8th October 2011, 09:46
  2. Replies: 6
    Last Post: 27th January 2011, 17:06
  3. How catch key press and key release for entire application
    By hubbobubbo in forum Qt Programming
    Replies: 4
    Last Post: 1st June 2010, 20:53
  4. Problem in Mouse Press Events & Vectors
    By dheeraj in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2008, 18:08
  5. Replies: 2
    Last Post: 2nd April 2008, 14:19

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.