[Solved][Alternative]Click event using eventfilter in QlineEdit



  • 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



  • I recommend you use "QLineEdit::placeholderText":http://doc.qt.nokia.com/latest/qlineedit.html#placeholderText-prop



  • 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???



  • [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.



  • Blimey!!!
    you jus saved me from big trouble :D saved around 20LOC :)
    It is the newbie in me :D

    Thank you

    alfah


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.