Last active
December 20, 2015 16:18
-
-
Save ivoflipse/6160297 to your computer and use it in GitHub Desktop.
Small example of using a grid layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide import QtGui | |
import sys | |
class MainWindow(QtGui.QMainWindow): | |
def __init__(self, parent=None): | |
super(MainWindow, self).__init__(parent) | |
self.input_widget = InputWidget(self) | |
self.layout = QtGui.QVBoxLayout() | |
self.layout.addWidget(self.input_widget) | |
self.setLayout(self.layout) | |
self.setCentralWidget(self.input_widget) | |
class InputWidget(QtGui.QWidget): | |
def __init__(self, parent): | |
super(InputWidget, self).__init__(parent) | |
self.grid_layout = QtGui.QGridLayout() | |
self.labels = ["amp", "more text", "blabla"] | |
self.text_edits = [] | |
self.qlabels = [] | |
for row, label in enumerate(self.labels): | |
label = QtGui.QLabel(label) | |
self.qlabels.append(label) | |
self.grid_layout.addWidget(label, row, 0) | |
text_edit = QtGui.QTextEdit() | |
self.text_edits.append(text_edit) | |
self.grid_layout.addWidget(text_edit, row, 1) | |
self.grid_layout.setColumnStretch(0, 0) | |
self.grid_layout.setColumnStretch(1, 2) | |
self.setLayout(self.grid_layout) | |
if __name__ == "__main__": | |
app = QtGui.QApplication(sys.argv) | |
window = MainWindow() | |
window.show() | |
app.exec_() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment