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

  • 相关阅读:
    HTML5和CSS3的学习视频
    webpack中bundler源码编写2
    webpack中bundler源码编写
    webpack中如何编写一个plugin
    webpack多页面打包配置
    webpack中配置eslint
    webpack解决单页面路由问题
    webpack中使用WebpackDevServer实现请求转发
    webpack中typeScript的打包配置
    rsync 同步
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4435519.html
Copyright © 2011-2022 走看看