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.

Figure: Absolute positioning

时间: 2024-08-15 11:30:08

Absolute positioning的相关文章

绝对定位( Absolute positioning )

绝对定位( Absolute positioning ) 之前在介绍定位体系的时候,已经简单的介绍了绝对定位和固定定位.一般情况下,这两种定位的元素, 在 3D 的可视化模型中,处于浮动元素的上方,或者说比浮动元素更靠前1. 参照元素 绝对定位(Absolute positioning)元素定位的参照物是其包含块,既相对于其包含块2进行定位,不一定是其父元素. 示例代码: <div style="position:relative; width:300px; height:300px; b

CSS 中 Position relative 和 absolute区别

Relative Positioning A relative positioned element is positioned relative to its normal position. The reserved space for the element is still preserved in the normal flow. relative 位置是相对元素的父元素的位置.left, top 是相对其父元素进行调整, 但是位置还是和DOM中的看起来一致(in normal flo

CSS Positioning(定位)与Float(浮动)

一.CSS Positioning(定位) 1.Positioning(定位) CSS定位属性允许你为一个元素定位.它也可以将一个元素放在另一个元素后面,并指定一个元素的内容太大时,应该发生什么.元素可以使用的顶部,底部,左侧和右侧属性定位.然而,这些属性无法工作,除非是先设定position属性.他们也有不同的工作方式,这取决于定位方法.有四种不同的定位方法. 2.Static 定位 HTML元素的默认值,即没有定位,元素出现在正常的流中.静态定位的元素不会受到top, bottom, lef

html 元素定位position-relative, absolute, fixed, static

看到这个,你有什么想法? Difference between static and relative positioning 如果你能完全看明白,那几本上css 元素定位的东西基本都会了.本文也不用往下看了. 自己接触web这么多年,虽说前端有接触过,但还是没有系统地学习过,和完整的实践过.很多东西是似懂非懂.其实这里就是问题的关键所在. 似懂非懂,其实本质上是不懂的.但是却又自以为懂, 这就是自己给自己设定了个障碍,这个障碍看似无形却比有形的障碍更可怕.因为每个人似乎 总是自以为是的认为自己

定位方案(Positioning schemes)

在这个系列第一章里可视化格式模型里就说到过,影响框的布局的几个因素: 1.框的尺寸和类型 2.定位体系 3.文档树中元素间的关系 4.外部信息 其中,我觉得在实际工作中处理最多的还要属定位体系的问题.定位体系,主要分三种,常规流(normal flow).浮动(floats).绝对定位(absolute positioning),这一节将大致的描述一下这三种定位体系,有一个大概的印象,知道到底是什么,然后后面的章节会一个一个具体的分析. 一.常规流 从直观上理解,常规流指的是html中的元素,按

10步掌握CSS布局定位: position static relative absolute float

无意中看到此文,因作者强调其中避开了浏览器bug/分歧,所以个人认为值得借鉴. 不才仔细看了此文,自觉受益匪浅 ,屡试不爽,佩服作者对css布局的精炼总结,顺便小译了一段, 英文水平有限,且个人通常写写php,对css了解不深却有点兴趣,错误之处还请指正. 个人没有空间,代码中的css文件和js保留了完整路径:http://www.barelyfitz.com/screencast/html-training/css/positioning/ 原文地址:http://www.barelyfitz

float和position:absolute脱离文本流的区别

float和position:absolute脱离文本流的区别原创 paediatrician 最后发布于2016-09-19 10:43:05 阅读数 5375 收藏展开 文档流:将窗体自上而下分成一行行, 并在每行中按从左至右的顺序排放元素,块状元素独占一行,内联元素不独占一行: CSS中脱离文档流,也就是将元素从普通的布局排版中拿走,其他盒子在定位的时候,会当做脱离文档流的元素不存在而进行定位. 需要注意的是,使用float脱离文档流时,其他盒子会无视这个元素,但其他盒子内的文本依然会为这

可视化格式模型(visual formatting model)

对于可视化格式模型这个概念,官方的原话是这样的:How use agents process the document tree for visual media.翻译过来就是用户端在媒介中如何处理文档树.用户端这个对于我们来说通常指的就是浏览器.媒介呢,就是展示页面的介质,比如显示器.文档树呢,就是源文档中元素树的编码.树中,每一个元素恰好有一个父元素,当然除了根元素. 一.框的布局影响因素 可视化格式模型中,每一个文档树中得元素都会根据box module(盒模型)来产生零个或多个控制框.这

wxpython 布局管理

一个典型的应用程序是由不同的部件.这些小部件被放进容器部件.一个程序员必须管理应用程序的布局.这不是一项容易的任务.在wxPython我们有两个选择. *absolute positioning*sizers Absolute Positioning绝对位置 程序员指定位置和大小的每个小部件以像素为单位.当你使用绝对定位,你必须了解一些事情. 1.如果你改变窗口大小,大小和位置的一个小部件不改变 2.在各种平台上的应用程序看起来不同 3.更改字体在您的应用程序可能会破坏布局 4.如果你决定改变你