-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtextwidget.cpp
More file actions
executable file
·31 lines (29 loc) · 959 Bytes
/
textwidget.cpp
File metadata and controls
executable file
·31 lines (29 loc) · 959 Bytes
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
#include "textwidget.h"
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
#include <QApplication>
#include <QHBoxLayout>
TextWidget::TextWidget(const QString &fileName)
{
QHBoxLayout *layout=new QHBoxLayout;
textEdit = new QTextEdit;
layout->addWidget(textEdit);
setLayout(layout);
loadFile(fileName);
}
void TextWidget::loadFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QFile::ReadOnly | QFile::Text)) {//打开失败或格式不对
QMessageBox::warning(this, tr("SDI"),
tr("Cannot read file %1:\n%2.")
.arg(fileName)
.arg(file.errorString()));
return;
}
QTextStream in(&file);
QApplication::setOverrideCursor(Qt::WaitCursor);
textEdit->setPlainText(in.readAll());//将内容显示在textEdit中
QApplication::restoreOverrideCursor();
}