3

HTML テーブルの幅を設定してQTextEdit、インライン スタイルシートで全体の幅を取得しようとしていますが、テーブルの幅は変わりません。パーセンテージ (%) やピクセル (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()

よろしくお願いします。

4

1 に答える 1

5

これがあなたが探しているものかどうかを確認してください:

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>
            '''
于 2012-12-19T00:05:23.570 に答える