Advertisement
JonasL1

L5 - filechooser.cpp

Nov 18th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include "filechooser.h"
  2. #include <QFileDialog>
  3. #include <QLayout>
  4. #include <QLineEdit>
  5. #include <QPushButton>
  6. #include <QHBoxLayout>
  7.  
  8. FileChooser::FileChooser(QWidget *parent)
  9. : QWidget(parent)
  10. {
  11. lineEdit = new QLineEdit(this);
  12. button = new QPushButton(tr("..."), this);
  13.  
  14. lineEdit->setGeometry(5, 5, 200, 20);
  15. button->setGeometry(210, 5, 20, 20);
  16.  
  17. // enter your code here
  18. // create a layout, set it on the widget and add the two child widgets to it
  19. QHBoxLayout *layout = new QHBoxLayout(this);
  20. layout->addWidget(lineEdit);
  21. layout->addWidget(button);
  22. // make a signal-slot connection between the two widgets
  23. connect(button, SIGNAL(clicked()), this, SLOT(chooseFile()));
  24. }
  25.  
  26. void FileChooser::chooseFile() {
  27. // enter your code here
  28. // ask the user for a file name and set its path as text of lineEdit
  29. QString path = QFileDialog::getOpenFileName(this);
  30. lineEdit->setText(path);
  31. }
  32.  
  33. QString FileChooser::file() const
  34. {
  35. return lineEdit->text();
  36. }
  37.  
  38. void FileChooser::setFile(const QString &file)
  39. {
  40. lineEdit->setText(file);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement