简体   繁体   English

PySide QTextEdit html表格宽度

[英]PySide QTextEdit html table width

I am trying to set the width of my html table to acquire the total width of my QTextEdit by an inline stylesheet but the width of the table doesn't change. 我试图设置我的html表的宽度,以通过内联样式表获取我的QTextEdit的总宽度,但表的宽度不会改变。 I've tried to give it values in the forms of percentages(%) and even pixels(px) but nothing changes.. Could you please have a look? 我试图以百分比(%)和偶数像素(px)的形式给它值,但没有任何变化..你能看一下吗?

#!/usr/bin/env python2

import sys
from PySide import QtGui, QtCore

class MainWid(QtGui.QWidget):
    htmlTable = '''<table border="1" style="width:100%"> <!-- XXX Nothing happens!! -->
        <tr><th colspan="2">HEADER</th></tr>
        <tr><td>name</td><td>value</td></tr>
        <tr><td>name</td><td>value</td></tr>
    </table>'''
    def __init__(self, parent=None):
        super(MainWid, self).__init__(parent)
        self.initgui()

    def initgui(self):
        lay = QtGui.QVBoxLayout()
        txt = QtGui.QTextEdit(self)

        lay.addWidget(txt)
        txt.setReadOnly(True)
        txt.setHtml(self.htmlTable)

        self.setLayout(lay)
        self.show()

def main():
    app = QtGui.QApplication(sys.argv)
    wid = MainWid()
    sys.exit(app.exec_())

if __name__=="__main__":
    main()

I thank you all in advance. 我提前感谢你们。

See if this is what you are looking for: 看看这是否是您正在寻找的:

htmlTable = ''' <table border="1" width="100%">
                    <tr><th colspan="2">HEADER</th></tr>
                    <tr><td>name</td><td>value</td></tr>
                    <tr><td>name</td><td>value</td></tr>
                </table>
            '''

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM