0

Hi~Below is my simple code,SerieBox Widget is father widget and SerieBox Widget is son widget, I have set SerieBox Widget padding:0px; and QLabel Widget margin:0px; I imagine SerieBox Widget and QLabel Widget spacing is 0,but my assumption is wrong,They still have spacing,Is there a great god helping me

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *


class SerieBox(QWidget):
    def __init__(self, ):
        super(SerieBox, self).__init__()

        self.vbox = QVBoxLayout()
        self.setLayout(self.vbox)

        self.num1 = QLabel('1')
        self.num2 = QLabel('2')

        self.vbox.addWidget(self.num1, alignment=Qt.AlignLeft | Qt.AlignTop)
        self.vbox.addWidget(self.num2, alignment=Qt.AlignLeft | Qt.AlignBottom)
        self.setStyleSheet("""
                *{
             border-width: 1px;
             border-style: solid;
             border-color: #cdcdcd;
                min-width:200px;
                 max-width:200px;
                 min-height:200px;
                 max-height:200px;
                 margin:0px;
                 padding:0px;
                }
            QLabel{
                min-width:70px;
                 max-width:70px;
                 min-height:70px;
                 max-height:70px;
                 margin:0px;
                 padding:0px;
            }
        """)

    def paintEvent(self, evt):
        opt = QStyleOption()
        opt.initFrom(self)
        painter = QPainter(self)
        painter.setRenderHint(QPainter.Antialiasing)
        self.style().drawPrimitive(QStyle.PE_Widget, opt, painter, self)


class Example(QWidget):
    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.setGeometry(300, 300, 500, 300)
        box = QHBoxLayout()
        self.setLayout(box)
        box.addWidget(SerieBox())
        self.show()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
redj
  • 171
  • 1
  • 10

0 Answers0