zoukankan      html  css  js  c++  java
  • Absolute positioning

    The programmer specifies the position and the size of each widget in pixels. When you use absolute positioning, we have to understand the following limitations:

    • The size and the position of a widget do not change if we resize a window
    • Applications might look different on various platforms
    • Changing fonts in our application might spoil the layout
    • If we decide to change our layout, we must completely redo our layout, which is tedious and time consuming

    The following example will position widgets in absolute coordinates.

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    """
    ZetCode PyQt4 tutorial 
    
    This example shows three labels on a window
    using absolute positioning. 
    
    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):
            
            lbl1 = QtGui.QLabel('ZetCode', self)
            lbl1.move(15, 10)
    
            lbl2 = QtGui.QLabel('tutorials', self)
            lbl2.move(35, 40)
            
            lbl3 = QtGui.QLabel('for programmers', self)
            lbl3.move(55, 70)        
            
            self.setGeometry(300, 300, 250, 150)
            self.setWindowTitle('Absolute')    
            self.show()
            
    def main():
        
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

    We use the move() method to position our widgets. In our case these are labels. We position them by providing the x and y coordinates. The beginning of the coordinate system is at the left top corner. The x values grow from left to right. The y values grow from top to bottom.

    lbl1 = QtGui.QLabel('Zetcode', self)
    lbl1.move(15, 10)
    

    The label widget is positioned at x=15 and y=10.

    Absolute positioningFigure: Absolute positioning

  • 相关阅读:
    Centos7安装Docker
    [LeetCode] 651. 四键键盘 ☆☆☆(动态规划)
    一行代码就能解决的算法题
    博弈问题--石头游戏(动态规划)
    [LeetCode] 322. 零钱兑换 ☆☆☆(动态规划)
    java趣题
    [LeetCode] 516. 最长回文子序列 ☆☆☆(动态规划)
    [LeetCode] 337. 打家劫舍III ☆☆☆(动态规划)
    算法基础--贪心算法
    [LeetCode] 42. 接雨水 ☆☆☆☆☆(按列、动态规划、双指针)
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4435505.html
Copyright © 2011-2022 走看看