diff options
3 files changed, 20 insertions, 10 deletions
diff --git a/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc b/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc index ddea067b7..5a599a1b2 100644 --- a/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc +++ b/examples/webenginewidgets/markdowneditor/doc/src/markdowneditor.qdoc @@ -116,7 +116,8 @@ \printto connect The constructor first calls \c setupUi to construct the widgets and menu - actions according to the UI file. It then makes sure our custom + actions according to the UI file. The text editor font is set to one + with a fixed character width. It then makes sure our custom \c PreviewPage is used by the QWebEngineView instance in \c{ui->preview}. \printto ui->preview diff --git a/examples/webenginewidgets/markdowneditor/mainwindow.cpp b/examples/webenginewidgets/markdowneditor/mainwindow.cpp index 352b7944a..3c6705686 100644 --- a/examples/webenginewidgets/markdowneditor/mainwindow.cpp +++ b/examples/webenginewidgets/markdowneditor/mainwindow.cpp @@ -43,6 +43,7 @@ #include <QFile> #include <QFileDialog> +#include <QFontDatabase> #include <QMessageBox> #include <QTextStream> #include <QWebChannel> @@ -52,6 +53,7 @@ MainWindow::MainWindow(QWidget *parent) : ui(new Ui::MainWindow) { ui->setupUi(this); + ui->editor->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); PreviewPage *page = new PreviewPage(this); ui->preview->setPage(page); @@ -84,6 +86,19 @@ MainWindow::~MainWindow() delete ui; } +void MainWindow::openFile(const QString &path) +{ + QFile f(path); + if (!f.open(QIODevice::ReadOnly)) { + QMessageBox::warning(this, windowTitle(), + tr("Could not open file %1: %2").arg( + QDir::toNativeSeparators(path), f.errorString())); + return; + } + m_filePath = path; + ui->editor->setPlainText(f.readAll()); +} + bool MainWindow::isModified() const { return ui->editor->document()->isModified(); @@ -117,15 +132,7 @@ void MainWindow::onFileOpen() if (path.isEmpty()) return; - QFile f(path); - if (!f.open(QIODevice::ReadOnly)) { - QMessageBox::warning(this, windowTitle(), - tr("Could not open file %1: %2").arg( - QDir::toNativeSeparators(path), f.errorString())); - return; - } - m_filePath = path; - ui->editor->setPlainText(f.readAll()); + openFile(path); } void MainWindow::onFileSave() diff --git a/examples/webenginewidgets/markdowneditor/mainwindow.h b/examples/webenginewidgets/markdowneditor/mainwindow.h index 596b5c504..fc04f6beb 100644 --- a/examples/webenginewidgets/markdowneditor/mainwindow.h +++ b/examples/webenginewidgets/markdowneditor/mainwindow.h @@ -59,6 +59,8 @@ public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); + void openFile(const QString &path); + private slots: void onFileNew(); void onFileOpen(); |