How to make QTextTable to cover whole document width
Asked Answered
T

1

5

I am trying to make the QTextTable inside QTextDocument to have 100% or full width of the document. But there is no method in QTextTableFormat class to format the QTextTable to have 100% width. We can resize row and column but not overall table.

Is there any way I can achieve that, if you know how, please share. Thanks

Toweling answered 29/1, 2020 at 1:29 Comment(0)
P
6

Since QTextTableFormat inherits from QTextFrameFormat it also has the setWidth() method that allows you to set the width using QTextLength as a basis that can set the width as a percentage of the document width:

import sys

from PyQt5 import QtCore, QtGui, QtWidgets

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    w = QtWidgets.QTextEdit()
    table = w.textCursor().insertTable(4, 5)

    fmt = table.format()
    fmt.setWidth(QtGui.QTextLength(QtGui.QTextLength.PercentageLength, 100))
    table.setFormat(fmt)

    w.show()
    sys.exit(app.exec_())

enter image description here

Parlous answered 29/1, 2020 at 1:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.