Fill in lineedit from QFileDialog
Hi All,
I have a lineedit that I'd like to be filled in from a QFileDialog. However the way I'd like it to be filled is if the user clicks on the lineedit a QFiledialog opens and the user selects a file. However when I click on the ui and the line edit and go to slots there's no clicked(), what slot do I use to select "clicked on box". Thanks in advance :D
Re: Fill in lineedit from QFileDialog
Code:
void XXX::mySlot() {
if(path.isEmpty()) return;
ui->myLineDit->setText(path);
}
Re: Fill in lineedit from QFileDialog
If you want to detect clicks on the line edit, you'll either have to derive from QLineEdit and implement the mouse handling in your subclass, or create an event filter that does the mouse handling and install it on the normal QLineEdit instance.
Cheers,
_
Re: Fill in lineedit from QFileDialog
"If you want to detect clicks on the line edit, you'll either have to derive from QLineEdit and implement the mouse handling in your subclass, or create an event filter that does the mouse handling and install it on the normal QLineEdit instance."
Thanks so I take it this is not as easy as I thought and might need quite a bit more practice at Qt
Re: Fill in lineedit from QFileDialog
Quote:
Originally Posted by
knobby67
Thanks so I take it this is not as easy as I thought and might need quite a bit more practice at Qt
It is not difficult at all. Have a look at docs of QObject::installEventFilter(). You will want to handle QEvent::MouseButtonRelease.