Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
33{
34 QTextCursor cursor = editor->textCursor();
35 cursor.beginEditBlock();
36
38 QTextListFormat listFormat;
39
41 listFormat.setNumberPrefix("(");
42 listFormat.setNumberSuffix(")");
43
44 cursor.insertList(listFormat);
46
47 cursor.endEditBlock();
48}
void insertList()
The QKeySequence class encapsulates a key sequence as used by shortcuts.
void setCentralWidget(QWidget *widget)
Sets the given widget to be the main window's central widget.
QAction * addMenu(QMenu *menu)
Appends menu to the menu bar.
Definition qmenubar.cpp:768
The QMenu class provides a menu widget for use in menu bars, context menus, and other popup menus.
Definition qmenu.h:26
void addAction(QAction *action)
Appends the action action to this widget's list of actions.
Definition qwidget.cpp:3117
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
\reentrant \inmodule QtGui
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
QTextCursor textCursor() const
Returns a copy of the QTextCursor that represents the currently visible cursor.
void setDocument(QTextDocument *document)
void setStyle(Style style)
Sets the list format's style.
void setNumberSuffix(const QString &numberSuffix)
void setNumberPrefix(const QString &numberPrefix)
bool close()
Closes this widget.
Definition qwidget.cpp:8562
void setWindowTitle(const QString &)
Definition qwidget.cpp:6105
QCursor cursor
the cursor shape for this widget
Definition qwidget.h:135
#define SLOT(a)
Definition qobjectdefs.h:52
#define tr(X)
QMenuBar * menuBar
[0]