Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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


  • Lifetime Qt Champion

    hi
    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) {
    OpenDialog()
    TheOne->setText(xxx);
    }



  • 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