Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved][Alternative]Click event using eventfilter in QlineEdit
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Mobile and Embedded
5 Posts 2 Posters 5.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alfah
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cincirin
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alfah
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            alfah
            wrote on last edited by
            #5

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

            Thank you

            alfah

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved