Results 1 to 20 of 22

Thread: help needed in QMouseEvent

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question help needed in QMouseEvent

    i have lineEdit control & 2 Button i.e Enter and Clear
    When the User Presses Clear Button for 4 sec or more the text in the lineEdit should be cleared.

    I'm not able to capture the pressEvent on the clear button.
    Help Needed.

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    why do you use events? QPushButton has signal clicked. you can try to use in.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    Why ever you want to force the user to press a button 4 seconds, simply subclass QPushButton an implement QWidget::mousePressEvent ( QMouseEvent * event ). (and of course QWidget::mouseReleaseEvent ( QMouseEvent * event ) to measure the time)

    Lykurg

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

    aj2903 (14th February 2009)

  5. #4
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    here is how u do it buddy:

    first use setMouseTracking(true) for your button class. start a timer when the mousePressEvent comes. set a timeout for 4 seconds on the timer and on slot for timeout(), u can clear the text

    void YourButtonClass::mousePressEvent(QMouseEvent* event)
    {

    if (event->button() == Qt::LeftButton)
    {
    Timer->start(m_sec);
    m_bMouseButtonDown = true;
    }

    }

    void CAutoRepeatButton::mouseReleaseEvent(QMouseEvent* event)
    {

    if (event->button() == Qt::LeftButton)
    {
    m_pAutoRepeatTimer->stop();
    m_bMouseButtonDown = false;

    if (m_pAutoRepeatTimer->interval() == urInterval)
    {
    urSlot();
    }
    }
    }

    this should solve ur problem

  6. The following user says thank you to talk2amulya for this useful post:

    aj2903 (14th February 2009)

  7. #5
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    thanks to all for quick reply.

    hi talk2amulya,
    i'm using simple QPushButton,i have one problem, in your code :

    Qt Code:
    1. void YourButtonClass::mousePressEvent(QMouseEvent* event)
    2. {
    3.  
    4. if (event->button() == Qt::LeftButton)
    5. {
    6. Timer->start(m_sec);
    7. m_bMouseButtonDown = true;
    8. }
    To copy to clipboard, switch view to plain text mode 

    how can i replace YourButtonClass with QPushButton?
    is it possible?

  8. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    install event filter for you button.
    Qt Code:
    1. ...
    2. m_pb = new QPushButton(tr("Clear"), this);
    3. m_pb->installEventFilter(this);
    4. ...
    5. bool MyWidget::eventFilter(QObject *o, QEvent e)
    6. {
    7. if (o == m_pb && e->type() == QEvent::QEvent::MouseButtonPress) {
    8. QMouseEvent *me = static_cast<QMouseEvent *>(e);
    9. if (e->button() == Qt::LeftButton) {
    10. Timer->start(m_sec);
    11. m_bMouseButtonDown = true;
    12. return true;
    13. }
    14. }
    15. return QWidget::eventFilter(o, e);
    16. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. The following user says thank you to spirit for this useful post:

    aj2903 (14th February 2009)

  10. #7
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    hi spirit

    i have written the code in following manner :


    abc.h
    class abcublic QDialog,public QObject
    {
    Qt Code:
    1. protected :
    2. bool eventFilter(QObject *o,QEvent *e):
    To copy to clipboard, switch view to plain text mode 
    }

    I'm facing the following error:
    abc.h:70: error: only constructors take base initializers

    I don't know what the problem is ?
    Kindly correct me where i'm going wrong

    Thanks in Advanced

  11. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    Qt doesnt support multiply inheritance from QObject, so you have to correct your code like this
    Qt Code:
    1. class YourDialog: public QDialog
    2. {
    3. ...
    4. protected:
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. #9
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    after trying
    Qt Code:
    1. class YourDialog: public QDialog
    2. {
    3. ...
    4. protected:
    5. ...
    6. }
    To copy to clipboard, switch view to plain text mode 

    same error is occuring

  13. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    show whole header file, plz.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  14. #11
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    Here is the Header File

    Qt Code:
    1. #ifndef ABC_H
    2. #define ABC_H
    3.  
    4. #include <QDialog>
    5. #include <QTimer>
    6. #include <QMouseEvent>
    7.  
    8. class abc: public QDialog
    9. {
    10. Q_OBJECT
    11.  
    12. public:
    13. abc(QWidget *parent = 0);
    14. ~abc;
    15. public slots:
    16. void log_data_refresh();
    17. protected:
    18. void mousePressEvent(QMouseEvent *event);
    19. void mouseReleaseEvent(QMouseEvent *event);
    20. bool eventFilter(QObject *obj,QEvent *event):
    21.  
    22. private slots:
    23. ...
    24. void check_queue();
    25. void closeEvent(QCloseEvent *event);
    26. void showEvent(QShowEvent *event);
    27.  
    28. private:
    29. QTimer *timer;
    30. };
    31.  
    32. #endif
    To copy to clipboard, switch view to plain text mode 

  15. #12
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: help needed in QMouseEvent

    try to change ~abc; to ~abc();
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.