Created
January 1, 2021 13:13
pyqt5 : widget alignment in 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
class SurfViewer(QMainWindow): | |
def __init__(self, parent=None): | |
super(SurfViewer, self).__init__(parent=parent) | |
self.setFixedSize(300, 100) | |
self.wid = QWidget() | |
self.setCentralWidget(self.wid) | |
self.groups = QHBoxLayout(self.wid) | |
l_a1 = QLabel('A') | |
a = QVBoxLayout() | |
a.addWidget(l_a1) | |
l_a2 = QLabel('A') | |
l_b2 = QLabel('B') | |
a_b = QVBoxLayout() | |
a_b.addWidget(l_a2) | |
a_b.addWidget(l_b2) | |
l_a3 = QLabel('A') | |
l_b3 = QLabel('B') | |
l_c3 = QLabel('C') | |
a_b_c = QVBoxLayout() | |
a_b_c.addWidget(l_a3) | |
a_b_c.addWidget(l_b3) | |
a_b_c.addWidget(l_c3) | |
a.setAlignment(Qt.AlignTop) | |
a_b.setAlignment(Qt.AlignTop) | |
a_b_c.setAlignment(Qt.AlignTop) | |
self.groups.addLayout(a) | |
self.groups.addLayout(a_b) | |
self.groups.addLayout(a_b_c) | |
self.groups.setAlignment(Qt.AlignTop) | |
if __name__ == '__main__': | |
app = QApplication(sys.argv) | |
ex = SurfViewer() | |
ex.setWindowTitle('window') | |
ex.show() | |
sys.exit(app.exec_( )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/49127653/align-every-widget-of-a-qhboxlayout-to-the-top