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
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);
13 QTextEdit *textEdit = new QTextEdit;
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
40//! [0]
41 table->mergeCells(0, 0, 1, 2);
42//! [0] //! [1]
43 table->splitCell(0, 0, 1, 1);
44//! [1]
45
46 textEdit->show();
47 return app.exec();
48}
int main(int argc, char *argv[])
[ctor_close]