1

I have a QGridLayout to handle my widgets. The fact is they stay in the column I put them, without expanding on the whole width. Is there any option to tell the rows to expand completely ? The goal would be to mimic the behavior of a QHBoxLayout, but without using one.

Example:

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)

EDIT:

Here is an image of what I want, I obtained the result with a QHBoxLayout in the QGridLayout, for the line in red (what I try to do without):

http://i.imgur.com/HNNhJlp.png

And here is one with the default behavior of the QGridLayout. It's what I currently have:

http://i.imgur.com/xVQy5aI.png

4

1 回答 1

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_())
于 2013-08-26T15:50:08.417 回答