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
main.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 <QApplication>
4#include <QTextEdit>
5#include <QTextTable>
6
7int main(int argc, char * argv[])
8{
9 int rows = 6;
10 int columns = 2;
11
12 QApplication app(argc, argv);
14 QTextCursor cursor(textEdit->textCursor());
15 cursor.movePosition(QTextCursor::Start);
16
17 QTextTableFormat tableFormat;
18 tableFormat.setAlignment(Qt::AlignHCenter);
19 tableFormat.setCellPadding(2);
20 tableFormat.setCellSpacing(2);
21 QTextTable *table = cursor.insertTable(rows, columns);
22 table->setFormat(tableFormat);
23
24 QTextCharFormat boldFormat;
25 boldFormat.setFontWeight(QFont::Bold);
26
27 QTextBlockFormat centerFormat;
28 centerFormat.setAlignment(Qt::AlignHCenter);
29 cursor.mergeBlockFormat(centerFormat);
30
31 cursor = table->cellAt(0, 0).firstCursorPosition();
32 cursor.insertText(("Details"), boldFormat);
33
34 cursor = table->cellAt(1, 0).firstCursorPosition();
35 cursor.insertText("Alan");
36
37 cursor = table->cellAt(1, 1).firstCursorPosition();
38 cursor.insertText("5, Pickety Street");
39
41 table->mergeCells(0, 0, 1, 2);
43 table->splitCell(0, 0, 1, 1);
45
46 textEdit->show();
47 return app.exec();
48}
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
@ Bold
Definition qfont.h:70
void show()
Shows the item (items are visible by default).
void setAlignment(Qt::Alignment alignment)
Sets the paragraph's alignment.
void setFontWeight(int weight)
Sets the text format's font weight to weight.
\reentrant \inmodule QtGui
Definition qtextcursor.h:30
The QTextEdit class provides a widget that is used to edit and display both plain and rich text.
Definition qtextedit.h:27
void setAlignment(Qt::Alignment alignment)
Sets the table's alignment.
void setCellSpacing(qreal spacing)
Sets the cell spacing for the table.
void setCellPadding(qreal padding)
Sets the cell padding for the table.
\reentrant
Definition qtexttable.h:63
int main()
[0]
QCursor cursor
@ AlignHCenter
Definition qnamespace.h:148
GLenum GLenum GLsizei void * table
QGraphicsWidget * textEdit
QApplication app(argc, argv)
[0]