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].
Bookmarks