1 ############################################################################ 2 ## 3 ## Copyright (C) 2016 The Qt Company Ltd. 4 ## Contact: https://www.qt.io/licensing/ 5 ## 6 ## This file is part of the examples of Qt for Python. 7 ## 8 ## $QT_BEGIN_LICENSE:BSD$ 9 ## Commercial License Usage 10 ## Licensees holding valid commercial Qt licenses may use this file in 11 ## accordance with the commercial license agreement provided with the 12 ## Software or, alternatively, in accordance with the terms contained in 13 ## a written agreement between you and The Qt Company. For licensing terms 14 ## and conditions see https://www.qt.io/terms-conditions. For further 15 ## information use the contact form at https://www.qt.io/contact-us. 16 ## 17 ## BSD License Usage 18 ## Alternatively, you may use this file under the terms of the BSD license 19 ## as follows: 20 ## 21 ## "Redistribution and use in source and binary forms, with or without 22 ## modification, are permitted provided that the following conditions are 23 ## met: 24 ## * Redistributions of source code must retain the above copyright 25 ## notice, this list of conditions and the following disclaimer. 26 ## * Redistributions in binary form must reproduce the above copyright 27 ## notice, this list of conditions and the following disclaimer in 28 ## the documentation and/or other materials provided with the 29 ## distribution. 30 ## * Neither the name of The Qt Company Ltd nor the names of its 31 ## contributors may be used to endorse or promote products derived 32 ## from this software without specific prior written permission. 33 ## 34 ## 35 ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 36 ## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 37 ## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 38 ## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 39 ## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 40 ## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 41 ## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 42 ## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 43 ## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 44 ## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 ## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." 46 ## 47 ## $QT_END_LICENSE$ 48 ## 49 ############################################################################ 50 51 //! [0] //! [1] 52 cursor = QTextCursor(editor.textCursor()) 53 //! [0] 54 cursor.movePosition(QTextCursor.Start) 55 //! [1] 56 57 //! [2] 58 tableFormat = QTextTableFormat() 59 tableFormat.setBackground(QColor("#e0e0e0")) 60 QVector<QTextLength> constraints 61 constraints << QTextLength(QTextLength.PercentageLength, 16) 62 constraints << QTextLength(QTextLength.PercentageLength, 28) 63 constraints << QTextLength(QTextLength.PercentageLength, 28) 64 constraints << QTextLength(QTextLength.PercentageLength, 28) 65 tableFormat.setColumnWidthConstraints(constraints) 66 //! [3] 67 table = cursor.insertTable(rows, columns, tableFormat) 68 //! [2] //! [3] 69 70 //! [4] 71 cell = table.cellAt(0, 0) 72 cellCursor = cell.firstCursorPosition() 73 cellCursor.insertText(tr("Week"), charFormat) 74 //! [4] 75 76 //! [5] 77 for column in range(columns): 78 cell = table.cellAt(0, column) 79 cellCursor = cell.firstCursorPosition() 80 cellCursor.insertText(tr("Team %1").arg(column), charFormat) 81 82 83 for row in range(rows): 84 cell = table.cellAt(row, 0) 85 cellCursor = cell.firstCursorPosition() 86 cellCursor.insertText(tr("%1").arg(row), charFormat) 87 88 for column in range(columns) 89 if (row-1) % 3 == column-1: 90 //! [5] //! [6] 91 cell = table.cellAt(row, column) 92 cellCursor = cell.firstCursorPosition() 93 cellCursor.insertText(tr("On duty"), charFormat) 94 95 //! [6] //! [7] 96 97 //! [7] //! [8] 98 99 //! [8] 100 101 //! [9] 102 for row in range(table.rows()): 103 for column in range(table.columns()): 104 tableCell = table.cellAt(row, column) 105 //! [9] 106 QTextFrame.iterator it 107 QString text 108 for (it = tableCell.begin() !(it.atEnd()); ++it): 109 QTextBlock childBlock = it.currentBlock() 110 if (childBlock.isValid()) 111 text += childBlock.text() 112 113 Item = QTableWidgetItem(text) 114 tableWidget.setItem(row, column, Item) 115 116 //! [10] 117 processTableCell(tableCell) 118 //! [10] 119 120 //! [11] 121 122 //! [11] //! [12] 123 124 //! [12] 125 126