我有一个QGridLayout来处理我的小部件。事实上,他们留在我放置的列中,而不是扩展整个宽度。是否有任何选项可以告诉行完全展开?目标是模仿QHBoxLayout的行为,但不使用一个。
示例:
self.label_player = QtGui.QLabel("Chemin du lecteur :")
self.line_path = QtGui.QLineEdit()
self.button_select_player = QtGui.QPushButton("Sélectionner")
...Some code
self.grid_settings.addWidget(self.label_player, 3, 0, 2, 1)
self.grid_settings.addWidget(self.line_path, 3, 1, 1, 1)
self.grid_settings.addWidget(self.button_select_player, 3, 2, 1, 1)
编辑:
这是我想要的图像,我在QGridLayout中使用QHBoxLayout获取结果,红色线条(我尝试不用):
http://i.imgur.com/HNNhJlp.png
这里有一个QGridLayout的默认行为。这就是我现在所拥有的:
答案 0 :(得分:1)
import sys
from PySide import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.grid = QtGui.QGridLayout()
big_one = QtGui.QPushButton('Big one')
big_one.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
self.grid.addWidget(big_one, 0, 0, 2, 2)
self.grid.addWidget(QtGui.QPushButton('Ajouter'), 0, 2, 1, 1)
self.grid.addWidget(QtGui.QPushButton('Enlever'), 1, 2, 1, 1)
self.grid.addWidget(QtGui.QLabel("Chemin du lecteur :"), 2, 0, 1, 1)
self.grid.addWidget(QtGui.QLineEdit(), 2, 1, 1, 1)
self.grid.addWidget(QtGui.QPushButton("Selectionner"), 2, 2, 1, 1)
self.grid.addWidget(QtGui.QCheckBox("Some long text in french"), 3, 0, 1, 3)
self.grid.addWidget(QtGui.QCheckBox("An even longer text in french than the first one"), 4, 0, 1, 3)
self.grid.addWidget(QtGui.QLabel("Something, something, something"), 5, 0, 1, 2)
self.grid.addWidget(QtGui.QSpinBox(), 5, 2, 1, 1)
self.setLayout(self.grid)
app = QtGui.QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())