Getting event filter to detect which line edit is clicked

  • Hi All,
    I have a form with a number of line edits, when the user right clicks on a line edit I want to set up an even filter that opens a file dialog to allow the line edit to be filled with a file name. I've worked out how to get event filters running with a left click, however how do I determine if its line edit 1,2,3 ect?

  • Qt Champions 2017

    you get the lineedit in
    eventFilter( QObject * object ...)

    So object is the line edit.
    you can then cast it to lineedit.
    QLineEdit *TheOne= qobject_cast<QLineEdit *>(object ) ;
    if (TheOne) {

  • Thanks for the advise

  • Moderators

    As a side note: Opening a file browse dialog on a right click is not a very common behavior. Usually a small "..." button next to the edit is used for this sort of thing, so a user can discover it easily. It also makes connecting it to the right open function easier.

Log in to reply

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