-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathOpenFileDialog.h
More file actions
39 lines (35 loc) · 1.03 KB
/
Copy pathOpenFileDialog.h
File metadata and controls
39 lines (35 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <QFileDialog>
#include <QFrame>
#include <QLabel>
#include <QMainWindow>
#include <QPushButton>
#include <QStandardPaths>
namespace Examples {
class Window1 : public QMainWindow {
Q_OBJECT
public:
Window1() {
button.setText("Open...");
button.move(10, 10);
connect(&button, &QPushButton::clicked, [&] {
QFileDialog openFileDialog;
openFileDialog.setNameFilters({"Text Files (*.txt)", "All Files (*)"});
openFileDialog.setDirectory(QStandardPaths::writableLocation(QStandardPaths::DesktopLocation));
if (openFileDialog.exec() == QDialog::Accepted) {
label.setText(QString("File = %1").arg(openFileDialog.selectedFiles()[0]));
label.resize(label.sizeHint());
}
});
label.move(10, 50);
label.setText("File = ");
setCentralWidget(&frame);
setWindowTitle("Open file dialog example");
resize(300, 300);
}
private:
QFrame frame;
QPushButton button {&frame};
QLabel label {&frame};
};
}