textedit.cpp Example File | Qt 4.8 (original) (raw)
help/simpletextviewer/textedit.cpp
#include <QtCore/QFileInfo> #include <QtCore/QFile>
#include "textedit.h"
TextEdit::TextEdit(QWidget *parent) : QTextEdit(parent) { setReadOnly(true); }
void TextEdit::setContents(const QString &fileName) { QFileInfo fi(fileName); srcUrl = QUrl::fromLocalFile(fi.absoluteFilePath()); QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { QString data(file.readAll()); if (fileName.endsWith(".html")) setHtml(data); else setPlainText(data); } }
QVariant TextEdit::loadResource(int type, const QUrl &name) { if (type == QTextDocument::ImageResource) { QFile file(srcUrl.resolved(name).toLocalFile()); if (file.open(QIODevice::ReadOnly)) return file.readAll(); } return QTextEdit::loadResource(type, name); }
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.