[PyQt] pyuic4 generates invalid method call QFormLayout.addLayout()

Сыр Российский cblp at cblp.su
Tue Mar 17 06:00:34 GMT 2009


Test form:

<ui version="4.0" >
 <class>Form</class>
 <widget class="QWidget" name="Form" >
  <property name="geometry" >
   <rect>
    <x>0</x>
    <y>0</y>
    <width>200</width>
    <height>100</height>
   </rect>
  </property>
  <property name="windowTitle" >
   <string>Form</string>
  </property>
  <layout class="QFormLayout" name="formLayout" >
   <item row="0" column="0" >
    <widget class="QLabel" name="label" >
     <property name="text" >
      <string>TextLabel</string>
     </property>
    </widget>
   </item>
   <item row="0" column="1" >
    <layout class="QVBoxLayout" name="verticalLayout" >
     <item>
      <widget class="QLineEdit" name="lineEdit" />
     </item>
    </layout>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>


pyuic4 generated:
    ...
    self.formLayout.addLayout(self.verticalLayout, 0, 1, 1, 1)
    ...
while there must be:
    self.formLayout.setLayout(0, 1, self.verticalLayout)
Because there is no such method as QFormLayout.addLayout().


Test case and workaround:

#! /usr/bin/env python2.5

from PyQt4 import QtGui

from ui_test import Ui_Form

def QFormLayout_addLayout(self, layout, row, column, rowSpan,
columnSpan, alignment=0):
    if column == 0:
        role = QtGui.QFormLayout.LabelRole
    else:
        role = QtGui.QFormLayout.FieldRole
    if rowSpan != 1 or columnSpan != 1:
        raise ValueError('rowSpan and columnSpan must be 1')
    self.setLayout(row, role, layout)

QtGui.QFormLayout.addLayout = QFormLayout_addLayout

class MainDialog(QtGui.QWidget, Ui_Form):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.setupUi(self)


Additional information:
    package version: pyqt4-dev-tools/4.4.3-1ubuntu1


More information about the PyQt mailing list