[PyKDE] Problem with layout iterators

Phil Thompson phil at riverbankcomputing.co.uk
Sun Jul 10 11:20:21 BST 2005


On Saturday 09 July 2005 2:53 pm, Baz Walter wrote:
> Hello again
>
> My earlier post on this got no response, so I suppose my description of the
> problem was no good :-(
>
> So - I hope this is a bit clearer:
>
> QLayoutIterator should produce objects which *inherit* QLayoutItem (such as
> a QLayout, QWidgetItem or QSpacerItem). However, it currently produces only
>
> "bare" QLayoutItems:
> >>> # using python 2.4.1 pyqt 3.14.1 and sip 4.2.1
> >>> from qt import *
> >>> a = QApplication([])
> >>> d = QFileDialog()
> >>> c = d.layout().iterator().current()
> >>> type(c).mro()
>
> [<class 'qt.QLayoutItem'>, <type 'sip.wrapper'>, <type 'object'>]
>
> This is wrong, because QLayoutItem is an abstract class only intended for
> sub-classing. It matters, because a "bare" QLayoutItem can only produce
> empty
>
> iterators and has no access to the object it is laying out:
> >>> if not c.isEmpty(): repr(c.iterator().current())
>
> 'None'
>
> >>> repr(c.layout()) # sub-class would return a QHBoxLayout, here
>
> 'None'
>
> Can this be fixed, so that only the correct sub-classes are produced by the
> layout iterators, please?

Ok, I've managed to extract enough type information to make this work. The 
following code...

from qt import *

a = QApplication([])

d = QFileDialog()
i = d.layout().iterator()

c = i.current()
while c:
    print c
    c = i.next()

...will generate the following output...

<qt.QHBoxLayout object at 0x2aaaae656f58>
<qt.QVBoxLayout object at 0x2aaaae6570d8>
<qt.QHBoxLayout object at 0x2aaaae656f58>

You will need tonight's PyQt snaphot built with tonight's SIP snapshot. (The 
SIP changes were needed to handle QLayout's multiple inheritance.)

Phil




More information about the PyQt mailing list