zoukankan      html  css  js  c++  java
  • GridLayout with span

    Widgets can span multiple columns or rows in a grid. In the next example we illustrate this.

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    """
    ZetCode PyQt4 tutorial 
    
    In this example, we create a bit
    more complicated window layout using
    the QtGui.QGridLayout manager. 
    
    author: Jan Bodnar
    website: zetcode.com 
    last edited: October 2011
    """
    
    import sys
    from PyQt4 import QtGui
    
    
    class Example(QtGui.QWidget):
        
        def __init__(self):
            super(Example, self).__init__()
            
            self.initUI()
            
        def initUI(self):
            
            title = QtGui.QLabel('Title')
            author = QtGui.QLabel('Author')
            review = QtGui.QLabel('Review')
    
            titleEdit = QtGui.QLineEdit()
            authorEdit = QtGui.QLineEdit()
            reviewEdit = QtGui.QTextEdit()
    
            grid = QtGui.QGridLayout()
            grid.setSpacing(10)
    
            grid.addWidget(title, 1, 0)
            grid.addWidget(titleEdit, 1, 1)
    
            grid.addWidget(author, 2, 0)
            grid.addWidget(authorEdit, 2, 1)
    
            grid.addWidget(review, 3, 0)
            grid.addWidget(reviewEdit, 3, 1, 5, 1)
            
            self.setLayout(grid) 
            
            self.setGeometry(300, 300, 350, 300)
            self.setWindowTitle('Review')    
            self.show()
            
    def main():
        
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

    We create a window in which we have three labels, two line edits, and one text edit widget. The layout is done with the QtGui.QGridLayout.

    grid = QtGui.QGridLayout()
    grid.setSpacing(10)
    

    We create a grid layout and set spacing between widgets.

    grid.addWidget(reviewEdit, 3, 1, 5, 1)
    

    If we add a widget to a grid, we can provide row span and column span of the widget. In our case, we make the reviewEdit widget span 5 rows.

    Review exampleFigure: Review example

  • 相关阅读:
    codechef Graph on a Table
    CF1063F. String Journey
    BZOJ1547: 周末晚会
    maxsigma
    LOJ#2351. 「JOI 2018 Final」毒蛇越狱
    BZOJ3632: 外太空旅行
    图论:tarjan相关算法复习
    Codeforces 321E. Ciel and Gondolas(凸优化+决策单调性)
    5031. 【NOI2017模拟3.27】B (k次狄利克雷卷积)
    CSAcademy Round 10 Yury's Tree(有根树点分树或kruskal重构树)
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4435519.html
Copyright © 2011-2022 走看看