Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "filechooser.h"
- #include <QFileDialog>
- #include <QLayout>
- #include <QLineEdit>
- #include <QPushButton>
- #include <QHBoxLayout>
- FileChooser::FileChooser(QWidget *parent)
- : QWidget(parent)
- {
- lineEdit = new QLineEdit(this);
- button = new QPushButton(tr("..."), this);
- lineEdit->setGeometry(5, 5, 200, 20);
- button->setGeometry(210, 5, 20, 20);
- // enter your code here
- // create a layout, set it on the widget and add the two child widgets to it
- QHBoxLayout *layout = new QHBoxLayout(this);
- layout->addWidget(lineEdit);
- layout->addWidget(button);
- // make a signal-slot connection between the two widgets
- connect(button, SIGNAL(clicked()), this, SLOT(chooseFile()));
- }
- void FileChooser::chooseFile() {
- // enter your code here
- // ask the user for a file name and set its path as text of lineEdit
- QString path = QFileDialog::getOpenFileName(this);
- lineEdit->setText(path);
- }
- QString FileChooser::file() const
- {
- return lineEdit->text();
- }
- void FileChooser::setFile(const QString &file)
- {
- lineEdit->setText(file);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement