我有一个python代码:
#class...
def setupLayout(self):
self.resize(1000, 600)
label1 = QtGui.QLabel(u'<font color=green><b><i>Полученные сообщения:</i></b></font>')
label2 = QtGui.QLabel(u'<font color=green><b><i>Описание сообщений:</i></b></font>')
self.mainList = QtGui.QListWidget()
self.descList = QtGui.QListWidget()
grid = QtGui.QGridLayout()
grid.setSpacing(1)
grid.addWidget(label1, 1, 1)
grid.addWidget(label2, 1, 2)
grid.addWidget(self.mainList, 2, 1, 5, 1)
grid.addWidget(self.descList, 2, 2, 5, 1)
#other definitions....
我希望使用窗口标题缩短标签和面板之间的距离。
因此,如果我使用此代码,距离是好的,但listBoxes只保留一行:
grid.addWidget(self.mainList, 2, 1, 1, 1)
grid.addWidget(self.descList, 2, 2, 1, 1)
那我怎么能做一个小距离?
答案 0 :(得分:1)
我倾向于使用QGridLayout
来表示同质内容。出于您的目的,QHBoxLayout
和QVBoxLayout
的组合可以更好地发挥作用。
left = QtGui.QVBoxLayout()
# This makes the label take as little space as possible
# since QLabel's sizeHint is Minimum.
left.addWidget(label1, 0)
left.addWidget(self.mainList, 1)
right = QtGui.QVBoxLayout()
right.addWidget(label2, 0)
right.addWidget(self.descList, 1)
main = QtGui.QHBoxLayout()
main.addLayout(left, 1) # Both sides take the same amount of space.
main.addLayout(right, 1)