View Full Version : mousepress event
tpthyd
26th February 2009, 11:21
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
Lykurg
26th February 2009, 11:31
Simply use mousePressEvent with mouseMoveEvent!
mousePressEvent: bool isPressed = true;
mouseMoveEvent: if (isPressed) ...
mouseReleaseEvent: bool isPressed = false;
aamer4yu
26th February 2009, 12:57
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 ;)
bigkoma
15th May 2009, 22:16
Hi,
I describe a class parrent from QLineEdit :
#ifndef MOJEDIT_H
#define MOJEDIT_H
#include <QLineEdit>
class MojEdit : public QLineEdit
{
//Q_OBJECT
public:
MojEdit(QWidget *parent);
virtual void mouseMoveEvent(QMouseEvent * e);
};
#endif // MOJEDIT_H
& cpp
#include "mojedit.h"
#include <QMessageBox>
#include <QMouseEvent>
MojEdit::MojEdit(QWidget *parent) : QLineEdit(parent)
{
setFocusPolicy(Qt::StrongFocus);
}
void MojEdit::mouseMoveEvent(QMouseEvent * e)
{
QMessageBox::about(0,"ll","BAM");
if (e->button() == Qt::LeftButton)
{
QMessageBox::about(0,"ll","BAM");
}
else
QLineEdit::mouseMoveEvent(e);
}
I use it :
MojEdit *ed = new MojEdit(centralWidget);
ed->setObjectName(QString::fromUtf8("MojEdit"));
ed->setGeometry(QRect(60, 40, 113, 25));
And i have error :
/home/michal/jkk/mainwindow.cpp:10: error: no matching function for call to ‘MojEdit::MojEdit(<unresolved overloaded function type>)’
I add that if I have :
MojEdit *ed;
ed->setObjectName(QString::fromUtf8("MojEdit"));
ed->setGeometry(QRect(60, 40, 113, 25));
Then it program is compiled correct , but I can't run it:
Starting /home/michal/jkk/jkk...
The program has unexpectedly finished.
/home/michal/jkk/jkk exited with code 0
So, what's wrong ?
/>>>> Edit <<<<
Moderator can delete this post. I resolve my problem.
I replace : centralWidget to MainWindow::centralWidget() . :)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.