All pastes #1853331 Raw Edit

geometria de un form

public python v1 · immutable
#1853331 ·published 2010-03-26 20:45 UTC
rendered paste body
# -*- coding: utf-8 -*-import sysfrom PyQt4 import QtGui,uicdef widgetAbsGeom(widget):    '''Given a widget w, returns a 4-tuple of its    absolute geometry'''    r=widget.geometry()    x,y,w,h=r.x(), r.y(), r.width(), r.height()    if widget.parent() and widget.parent().parent():        # Then those coords were relative        px, py, pw, ph = widgetAbsGeom(widget.parent())        x+=px        y+=py        w+=pw        h+=ph    else:       # The parent is the top level,       # so the coords are absolute       pass    return x,y,w,h        def main():        app = QtGui.QApplication(sys.argv)    form = uic.loadUi('sample1.ui')    form.show()    # form is a QWidget that contains all of our    # "fields".    # So, find them!    labels = form.findChildren(QtGui.QLabel)    fields = form.findChildren(QtGui.QLineEdit)    print 'ETIQUETAS:'    print    for label in labels:        print label.objectName(), unicode(label.text())        print widgetAbsGeom(label)    print 'CAMPOS:'    print    for field in fields:        print field.objectName()        print widgetAbsGeom(field)main()