HTML <table> Does Not Fill QLabel

397 Views Asked by At

How can I make an html table to fill all the available space in the QLabel that the same html defines?

In this image the red should fill the black as the table being width and height at 100% should fill all of the available space of the QLabel which is in black: red=html black=resized QLabel

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import QCoreApplication

class Example(QWidget):

    def __init__(self):
        super().__init__()

        lbl1 = QLabel("""
        <style>
            table{
                background-color: red;
            }

        </style>

        <table width="100%" height="100%">
            <tr>
                <td colspan="2">1234</td>
            </tr>
            <tr>
                <td width="60">1</td>
                <td width="50">4</td>
            </tr>
        </table>
        """, self)
        lbl1.setStyleSheet('QFrame {background-color:black;}')

        lbl1.resize(200, 200)

        self.setGeometry(0, 0, 400, 220)

        self.show()

if __name__ == '__main__':

    app = QApplication(sys.argv)

    ex = Example()
    sys.exit(app.exec_())
0

There are 0 best solutions below