我正在申请PyQT4
。这个应用程序的主要部分将是维护一个小部件的网格(从QLineEdit
小部件分类)。我正在将这些小工具组织成QGridLayout
。QGridLayout中窗口小部件之间的间距如何在窗口大小上保持不变?
当我运行的窗口,我得到有组织的我是多么希望有一个网格,即
然而,QGridLayout
有当窗口大小,它会自动垫部件之间的间距属性,即
我将网格我如何调整窗口,喜欢有小部件之间的间距相同,不管。我看了,似乎无法找到如何完成这一点。我会想象一些可以修正间距的东西,但是没有任何可能的探测功能会产生这种效果。
这是下面的代码片段,特别是QGridLayout
的部分。
class GridBlockTxtbx(QtGui.QWidget):
def __init__(self, blocks=5, spaces=5):
QtGui.QWidget.__init__(self)
self.dctn_txtbx = {}
self.blocks = blocks
self.spaces = spaces
# Create layout
layout = QtGui.QGridLayout()
# Set initial spacing between widgets to 2 pixels...
# I want this to be fixed on window resize!
layout.setSpacing(2)
# Function to load the widgets into the grid
GridBlockTxtbx._gen_block_txtbx_grid(layout, self.blocks,
self.spaces,
self.dctn_txtbx)
# Set the layout
self.setLayout(layout)
def _gen_block_txtbx_grid(layout, rows, cols, dctn):
for i in range(rows):
for j in range(cols):
blk = GridBlockTxtbx._gen_block_txtbx(idx=(i, j))
layout.addWidget(blk, i, j)
dctn[i, j] = blk
如果你想有一个固定的间距,应发生什么upons调整呢?小部件是否应该变大或者如果网格获得更多的行和列或者网格外部是否有额外的空间?请指定所需的行为以使问题可以答复。 – Trilarion
Ekhumoro回答,谢谢:) –
这是真的。虽然他只是猜测,因为你没有指定你想要的。这使得这个问题对其他人不太有用 – Trilarion