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.
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.
why do you use events? QPushButton has signal clicked. you can try to use in.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
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
aj2903 (14th February 2009)
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
aj2903 (14th February 2009)
thanks to all for quick reply.
hi talk2amulya,
i'm using simple QPushButton,i have one problem, in your code :
Qt Code:
{ if (event->button() == Qt::LeftButton) { Timer->start(m_sec); m_bMouseButtonDown = true; }To copy to clipboard, switch view to plain text mode
how can i replace YourButtonClass with QPushButton?
is it possible?
install event filter for you button.
Qt Code:
... m_pb->installEventFilter(this); ... { if (e->button() == Qt::LeftButton) { Timer->start(m_sec); m_bMouseButtonDown = true; return true; } } }To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
aj2903 (14th February 2009)
hi spirit
i have written the code in following manner :
abc.h
class abcublic QDialog,public QObject
{
}Qt Code:
protected :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
Qt doesnt support multiply inheritance from QObject, so you have to correct your code like this
Qt Code:
{ ... protected: ... }To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
after trying
Qt Code:
{ ... protected: ... }To copy to clipboard, switch view to plain text mode
same error is occuring
show whole header file, plz.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Here is the Header File
Qt Code:
#ifndef ABC_H #define ABC_H #include <QDialog> #include <QTimer> #include <QMouseEvent> { Q_OBJECT public: ~abc; public slots: void log_data_refresh(); protected: private slots: ... void check_queue(); private: QTimer *timer; }; #endifTo copy to clipboard, switch view to plain text mode
try to change ~abc; to ~abc();
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
tried but same error.
try this change bool eventFilter(QObject *obj,QEvent *event): to bool eventFilter(QObject *obj,QEvent *event);
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
aj2903 (14th February 2009)
this was the real problem thanks spirit.
Wow,
first of all QWidget::setMouseTracking() is not needed. It is just for getting mouse move events which you aren't need. Then to use a QTimer is overkill because of all the signal and slots thing. Better use a simple QTime::currentTime (). Save the time stamp in press function and in the release function you just calculate the difference and if it is greater then 4 seconds emit a signal.
Lykurg
so that means using QTimer is more expensive than using QTime::currentTime()?
Because I have too much time, or better to much work to get around, here is an example:
Qt Code:
#ifndef MYBUTTON_H #define MYBUTTON_H #include <QtGui> { Q_OBJECT public: void setMinimumHoldTime(int msec) { m_minimumHoldTime = msec; } int minimumHoldTime() const { return m_minimumHoldTime; } protected: signals: void holdForMSec(int); private: QTime m_time; int m_minimumHoldTime; }; #endif // MYBUTTON_HTo copy to clipboard, switch view to plain text mode
Qt Code:
#include "mybutton.h" {} { } { int msec = m_time.elapsed(); // Do time check in the button class if (m_minimumHoldTime < msec && rect().contains(event->pos())) emit holdForMSec(msec); // or let the reciver decide what to do // if (rect().contains(event->pos())) // emit holdForMSec(msec); }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...
aj2903 (14th February 2009)
hi lykurg,
first of all, thanks for investing your time on this..i have one doubt abt what u said..does QTimer really start its own event loop..cuz as far as i've seen, exec() is the only way to start your own event loop..but its always good to know alternative ways to solve a problem..r u sure it starts its own event loop?
Bookmarks