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 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
edit = new QPlainTextEdit(this);
edit->resize(500,500);
edit->hide();
label = new QLabel(this);
label->resize(500,500);
label->hide();
btn_images = new QPushButton("Image Files", this);
btn_text = new QPushButton("Text Files", this);
btn_images->setGeometry(QRect(QPoint(0, 600), QSize(200, 50)));
btn_text->setGeometry(QRect(QPoint(0, 650), QSize(200, 50)));
connect(btn_images, &QPushButton::clicked, this, &MainWindow::images_click);
connect(btn_text, &QPushButton::clicked, this, &MainWindow::text_click);
}
void MainWindow::images_click()
{
fileName = QFileDialog::getOpenFileName(this,
tr("Open image files"), "",
tr("Images (*.bmp *.jpg);;All Files (*)"));
edit->hide();
label->show();
QPixmap pix(fileName);
label->setPixmap(pix);
}
void MainWindow::text_click()
{
edit->show();
label->hide();
fileName = QFileDialog::getOpenFileName(this,
tr("Open text files"), "",
tr("Documents (*.txt *.odt);;All Files (*)"));
QFile file(fileName);
file.open(QIODevice::ReadOnly);
QTextStream stream(&file);
QString content = stream.readAll();
file.close();
edit->setPlainText(content);
}
|