Results 1 to 20 of 22

Thread: help needed in QMouseEvent

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #19
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: help needed in QMouseEvent

    Because I have too much time, or better to much work to get around, here is an example:

    Qt Code:
    1. #ifndef MYBUTTON_H
    2. #define MYBUTTON_H
    3.  
    4. #include <QtGui>
    5.  
    6. class myButton : public QPushButton
    7. {
    8. Q_OBJECT
    9. public:
    10. myButton(QWidget *parent = 0);
    11. void setMinimumHoldTime(int msec)
    12. {
    13. m_minimumHoldTime = msec;
    14. }
    15. int minimumHoldTime() const
    16. {
    17. return m_minimumHoldTime;
    18. }
    19. protected:
    20. void mousePressEvent(QMouseEvent *event);
    21. void mouseReleaseEvent(QMouseEvent *event);
    22. signals:
    23. void holdForMSec(int);
    24. private:
    25. QTime m_time;
    26. int m_minimumHoldTime;
    27. };
    28.  
    29. #endif // MYBUTTON_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mybutton.h"
    2.  
    3. myButton::myButton(QWidget *parent)
    4. : QPushButton(parent), m_time(), m_minimumHoldTime(4000)
    5. {}
    6.  
    7. void myButton::mousePressEvent(QMouseEvent *event)
    8. {
    9. m_time = QTime::currentTime();
    10. QPushButton::mousePressEvent(event);
    11. }
    12.  
    13. void myButton::mouseReleaseEvent(QMouseEvent *event)
    14. {
    15. int msec = m_time.elapsed();
    16. // Do time check in the button class
    17. if (m_minimumHoldTime < msec && rect().contains(event->pos()))
    18. emit holdForMSec(msec);
    19. // or let the reciver decide what to do
    20. // if (rect().contains(event->pos()))
    21. // emit holdForMSec(msec);
    22. QPushButton::mouseReleaseEvent(event);
    23. }
    To copy to clipboard, switch view to plain text mode 

    @talk2amulya: If you call QTimer::start(int) you start a new "event loop" (I don't know how QTimer is exactly implemented), to measure when the time is up and at which end a signal is emitted. And this continuous! Whereas QTime simple returns a time Object. Nothing more...

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

    aj2903 (14th February 2009)

Similar Threads

  1. Qt4Libraries needed for using images
    By divya balachandran in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 21:52
  2. Using Map in Qwt Widget..help needed
    By swamyonline in forum Qwt
    Replies: 2
    Last Post: 11th June 2008, 19:53
  3. Forward declarations needed for some?
    By doktorn in forum Newbie
    Replies: 6
    Last Post: 28th November 2007, 08:56
  4. How to get color of pixel or point by QMouseEvent
    By Krishnacins in forum Newbie
    Replies: 4
    Last Post: 28th May 2006, 01:46

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.