Skip to content

Instantly share code, notes, and snippets.

@saleph
Created August 26, 2015 14:50
Show Gist options
  • Save saleph/d2a1f3cf1549aec4ee93 to your computer and use it in GitHub Desktop.
Save saleph/d2a1f3cf1549aec4ee93 to your computer and use it in GitHub Desktop.
[qt5] box layout
__author__ = 'tom'
import sys
from PyQt5.QtWidgets import (QWidget, QPushButton,
QHBoxLayout, QVBoxLayout, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
ok_btn = QPushButton('OK')
cancel_btn = QPushButton('Cancel')
h_box = QHBoxLayout()
h_box.addStretch(1) # add stretchable space on the left of the box
h_box.addWidget(ok_btn)
h_box.addWidget(cancel_btn)
v_box = QVBoxLayout()
v_box.addStretch(1)
v_box.addLayout(h_box)
self.setLayout(v_box)
self.setGeometry(300, 300, 300, 150)
self.setWindowTitle('Buttons')
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment