How to get Click Event of QLineEdit in Qt?

How to get Click Event of QLineEdit in Qt ?

I am not able to see any SLOT related to click in QLineEdit ?

Answers


You need to reimplement focusInEvent in a new class extending QLineEdit. The following links are going to help you.

  1. http://doc.qt.io/qt-5/qwidget.html#focusInEvent
  2. QLineEdit - focus event
  3. How to know if a QLineEdit got focus?
  4. QLineEdit Focus Event

I don't think subclassing a QLineEdit is the right choice. Why subclass if you don't need to? You could instead use event filters. Check out QObject::eventFilter.

Example:

MyClass::MyClass() :
    edit(new QLineEdit(this))
{
    edit->installEventFilter(this);
}

bool MyClass::eventFilter(QObject* object, QEvent* event)
{
    if(object == edit && event->type() == QEvent::FocusIn) {
        // bring up your custom edit
        return false; // lets the event continue to the edit
    }
    return false;
}

Although there is no "clicked" or "entered" event. You can use the

void cursorPositionChanged(int old, int new)

Signal. It is emitted when the user clicks the lineedit (if it is enabled) and also on a few other occasions so you have to verify which of the events actually happened but I think this is still easier than subclassing or using the event listener for some applications.


I dono if this will help, i had to call a function once a text is entered. This is how i did it.

connect(ui->passwordSetLineEdit,SIGNAL(textEdited(QString)),this,SLOT(onTextEdit(QString)));

when a text is entered textEdited signal will be emited, thus my onTextEdit function will be called.


There is no signals like clicked() for QLineEdit, but you can subclass it and emit such signal in your custom implementation of mouseReleaseEvent.


Need Your Help

Programmatically Logging Errors With Elmah : Logging specific information

.net asp.net exception exception-handling elmah

I am logging error with Elmah inside a try-catch block. here is the code;

Stop javascript Date function from changing timezone offset

javascript date datetime timezone

So I have iso date time that need to be converted from a string to date object. How do I keep date from converting it to local browser timezone.