Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
mainwindow.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3#include "mainwindow.h"
4
5#include <QMenu>
6#include <QMenuBar>
7#include <QTextEdit>
8
10{
11 QMenu *fileMenu = new QMenu(tr("&File"));
12
13 fileMenu->addAction(tr("E&xit"), QKeySequence(tr("Ctrl+Q", "File|Exit")),
14 this, SLOT(close()));
15
16 QMenu *insertMenu = new QMenu(tr("&Insert"));
17
18 insertMenu->addAction(tr("&List"), QKeySequence(tr("Ctrl+L", "Insert|List")),
19 this, SLOT(insertList()));
20
21 menuBar()->addMenu(fileMenu);
22 menuBar()->addMenu(insertMenu);
23
24 editor = new QTextEdit(this);
25 document = new QTextDocument(this);
26 editor->setDocument(document);
27
28 setCentralWidget(editor);
29 setWindowTitle(tr("Text Document List Item Styles"));
30}
31
32void MainWindow::insertList()
33{
34 QTextCursor cursor = editor->textCursor();
35 cursor.beginEditBlock();
36
37 //! [add a styled, ordered list]
38 QTextListFormat listFormat;
39
40 listFormat.setStyle(QTextListFormat::ListDecimal);
41 listFormat.setNumberPrefix("(");
42 listFormat.setNumberSuffix(")");
43
44 cursor.insertList(listFormat);
45 //! [add a styled, ordered list]
46
47 cursor.endEditBlock();
48}