[Solved][Alternative]Click event using eventfilter in QlineEdit
-
wrote on 25 Aug 2011, 11:09 last edited by
hey everybody
Im havin lil trouble with the eventfilters. I have a line edit which has the a default text"Click to change password". I want to clear the text automatically when the user presses the lineedit. Since line edit does not have a click event. I have used a event filter.
In the constructor of the class, I have set the following
@
ui->passwordSetLbl->installEventFilter(this);
@and this is my eventfilter
@
bool SettingForm::eventFilter(QObject *obj, QEvent *event)
{
if(obj==ui->passwordSetLbl)
{
if(event->type() == QEvent::MouseButtonPress)
{
checkClearPassword();
return true;
}
else
return false;} else { return QDialog::eventFilter(obj,event); }
}
@It works right for the first time. Suppose i write some text in the line edit, When i click on the LineEdit, nothing happens. Im not able to edit it again.!! :(
alfah
-
wrote on 25 Aug 2011, 11:14 last edited by
I recommend you use "QLineEdit::placeholderText":http://doc.qt.nokia.com/latest/qlineedit.html#placeholderText-prop
-
wrote on 25 Aug 2011, 11:27 last edited by
cincirin
could you explanin a bit more. I read the docs.
I need to jus the type the string i want to show as default inside the function setplaceholder??? -
wrote on 25 Aug 2011, 11:34 last edited by
[quote author="alfah" date="1314271672"]I need to jus the type the string i want to show as default inside the function setplaceholder???[/quote]
Yes :-) You don't need to install event filter for what you want. Just use setPlaceholderText function. -
wrote on 25 Aug 2011, 11:39 last edited by
Blimey!!!
you jus saved me from big trouble :D saved around 20LOC :)
It is the newbie in me :DThank you
alfah
1/5