Skip to content

Instantly share code, notes, and snippets.

@Park-Developer
Last active January 1, 2021 06:22
Show Gist options
  • Save Park-Developer/bd9f1b76dc812c22a5a9cb844a78ca80 to your computer and use it in GitHub Desktop.
Save Park-Developer/bd9f1b76dc812c22a5a9cb844a78ca80 to your computer and use it in GitHub Desktop.
pyqt5 : setRowStretch(), setColumnStretch()
import random
import sys
from PyQt5 import QtGui, QtWidgets
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
glay = QtWidgets.QGridLayout(w)
for i in range(3):
for j in range(3):
label = QtWidgets.QLabel("{}x{}".format(i, j))
color = QtGui.QColor(*random.sample(range(255), 3))
label.setStyleSheet("background-color: {}".format(color.name()))
glay.addWidget(label, i, j)
glay.setRowStretch(0, 1)
glay.setRowStretch(1, 2)
glay.setRowStretch(2, 3)
w.resize(640, 480)
w.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment