PDA

View Full Version : Fill in lineedit from QFileDialog



knobby67
18th August 2014, 10:59
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

wysota
18th August 2014, 13:10
void XXX::mySlot() {
QString path = QFileDialog::getOpenFileName(...);
if(path.isEmpty()) return;
ui->myLineDit->setText(path);
}

anda_skoa
18th August 2014, 17:50
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,
_

knobby67
18th August 2014, 17:56
"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

wysota
19th August 2014, 09:10
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.