减少 PyQt5 中的间距 - GridLayout - 小部件之间

Reduce spacing in PyQt5 - GridLayout - Between the widgets

我是 PyQt5 的新手,我创建了一个如图所示的网格布局我想减少三个小部件之间的间隙,我尝试过边距、间距和行拉伸但 none 奏效了,请查看超链接中的图像并帮助我:

图片:

def createlayout(self):
    self.label1=QLabel(self.label,self)
    self.label2=QLabel(self.label2,self)
    self.label3 = QLabel("try", self)
    self.textbox = QLineEdit(self)

    vbox=QGridLayout()


    vbox.addWidget(self.label1,0,0,1,1)

    vbox.addWidget(self.textbox,1,0,1,1)

    vbox.addWidget(self.label2,2,0,1,1)

    vbox.addWidget(self.label3, 3, 0, 1, 1)

    vbox.setContentsMargins(1,0,0,0)
    #vbox.setAlignment('AlignCenter')
    vbox.setRowStretch(0, 0)
    vbox.setRowStretch(1, 0)
    vbox.setRowStretch(2,0)
    vbox.setColumnStretch(1,0)
    #vbox.setRowStretch(2,1)
    vbox.setRowStretch(3,0)
    vbox.setSpacing(0)

QGridLayout::setRowStretch(int row, int stretch)

Sets the stretch factor of row row to stretch. The first row is number 0.

The stretch factor is relative to the other rows in this grid. Rows with a higher stretch factor take more of the available space.

The default stretch factor is 0. If the stretch factor is 0 and no other row in this table can grow at all, the row may still grow.

import sys
from PyQt5.Qt import *

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.createlayout()

    def createlayout(self):
        self.label1 = QLabel("self.label")
        self.label2 = QLabel("self.label2")
        self.label3 = QLabel("try", )
        self.textbox = QLineEdit()

        vbox = QGridLayout(self)
        vbox.addWidget(self.label1, 0, 0)
        vbox.addWidget(self.textbox, 1, 0)
        vbox.addWidget(self.label2, 2, 0)
        vbox.addWidget(self.label3, 3, 0)
        
        vbox.setRowStretch(4, 1)                                 # +++

        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = Window()
    w.resize(300, 200)
    w.show()
    sys.exit(app.exec_())