Results 1 to 4 of 4

Thread: mousepress event

  1. #1
    Join Date
    Feb 2009
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Post mousepress event

    hi,
    when i pressed the mouse, mousepressevent(Qmouseevent *event) is receving event. even if i hold the mouse button for sometime , mousepressevent() is calling only once. i want to call this event utill i released the mouse button. can anyone suggest me how to do this.

    thanks and regards
    sandeep

  2. #2
    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: mousepress event

    Simply use mousePressEvent with mouseMoveEvent!

    mousePressEvent: bool isPressed = true;
    mouseMoveEvent: if (isPressed) ...
    mouseReleaseEvent: bool isPressed = false;

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousepress event

    What widget are you trapping the mousePressEvent for ?

    If it is a button, you could very well use QAbstractButton::setAutoRepeat
    Otherwise, on mouse press start you timer with some interval. and on mouse release stop this timer. Hope its not that difficult

  4. #4
    Join Date
    Feb 2009
    Location
    Bydgoszcz, Poland
    Posts
    16
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousepress event

    Hi,

    I describe a class parrent from QLineEdit :


    Qt Code:
    1. #ifndef MOJEDIT_H
    2. #define MOJEDIT_H
    3.  
    4. #include <QLineEdit>
    5.  
    6. class MojEdit : public QLineEdit
    7. {
    8. //Q_OBJECT
    9.  
    10. public:
    11. MojEdit(QWidget *parent);
    12. virtual void mouseMoveEvent(QMouseEvent * e);
    13.  
    14. };
    15.  
    16. #endif // MOJEDIT_H
    To copy to clipboard, switch view to plain text mode 
    & cpp
    Qt Code:
    1. #include "mojedit.h"
    2. #include <QMessageBox>
    3. #include <QMouseEvent>
    4.  
    5. MojEdit::MojEdit(QWidget *parent) : QLineEdit(parent)
    6. {
    7. setFocusPolicy(Qt::StrongFocus);
    8. }
    9.  
    10. void MojEdit::mouseMoveEvent(QMouseEvent * e)
    11. {
    12. QMessageBox::about(0,"ll","BAM");
    13.  
    14. if (e->button() == Qt::LeftButton)
    15. {
    16. QMessageBox::about(0,"ll","BAM");
    17. }
    18. else
    19. QLineEdit::mouseMoveEvent(e);
    20. }
    To copy to clipboard, switch view to plain text mode 

    I use it :
    Qt Code:
    1. MojEdit *ed = new MojEdit(centralWidget);
    2. ed->setObjectName(QString::fromUtf8("MojEdit"));
    3. ed->setGeometry(QRect(60, 40, 113, 25));
    To copy to clipboard, switch view to plain text mode 
    And i have error :
    Qt Code:
    1. /home/michal/jkk/mainwindow.cpp:10: error: no matching function for call to ‘MojEdit::MojEdit(<unresolved overloaded function type>)’
    To copy to clipboard, switch view to plain text mode 
    I add that if I have :
    Qt Code:
    1. MojEdit *ed;
    2. ed->setObjectName(QString::fromUtf8("MojEdit"));
    3. ed->setGeometry(QRect(60, 40, 113, 25));
    To copy to clipboard, switch view to plain text mode 
    Then it program is compiled correct , but I can't run it:

    Qt Code:
    1. Starting /home/michal/jkk/jkk...
    2.  
    3. The program has unexpectedly finished.
    4.  
    5. /home/michal/jkk/jkk exited with code 0
    To copy to clipboard, switch view to plain text mode 
    So, what's wrong ?

    />>>> Edit <<<<

    Moderator can delete this post. I resolve my problem.

    I replace : centralWidget to MainWindow::centralWidget() .
    Last edited by bigkoma; 15th May 2009 at 21:25.

Similar Threads

  1. mousepress event
    By tpthyd in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2009, 15:02
  2. Replies: 4
    Last Post: 19th February 2009, 11:10
  3. Custom event gets not propagated to the top level widget
    By nightghost in forum Qt Programming
    Replies: 0
    Last Post: 29th January 2009, 09:06
  4. Event propagation direction
    By spraff in forum Qt Programming
    Replies: 0
    Last Post: 6th December 2008, 21:03
  5. Qt event queue overloading?
    By gct in forum Qt Programming
    Replies: 3
    Last Post: 17th March 2008, 18:39

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.