On Friday 25 April 2008, Alberto Berti wrote:
> Hello all,
>
> I have some code that while uiparser.py reads an .ui file, it hooks in
> the process and binds the widget to the correct data context (read:
> tablemodel). It uses the child to parent widget "navigation" using
> QObject.parent() to find out the correct context for a widget. It
> works very well, except for some cases where parent chain is broken
> and so an exception is raised. This error happens only when one of the
> widgets which are "decorated" is  contained, for example, in a
> QTabWidget's page. The interesting piece of the .ui file appears like
> this:
>
>       <widget class="QTabWidget" name="tabWidget" >
>       <property name="geometry" >
>         <rect>
>           ...
>         </rect>
>       </property>
>       <property name="tabShape" >
>         <enum>QTabWidget::Rounded</enum>
>        </property>
>        <widget class="QWidget" name="tab" >
>        <property name="geometry" >
>          <rect>
>            ...
>          </rect>
>        </property>
>        <attribute name="title" >
>          <string>Tab 1</string>
>        </attribute>
>        <widget class="QComboBox" name="tipologiaoperazione" >
>          <property name="geometry" >
>            <rect>
>              ...
>            </rect>
>          </property>
>          <property name="column" stdset="0" >
>            <string>tipologiaoperazione</string>
>          </property>
>        </widget>
>        </widget>
>       </widget>
>
>
> So the QTabWidget's page is "rendered" by Qt Designer as a simple
> QWidget, and this is the object where the .parent() chain
> breaks. While looking for source of this problem, I discovered a
> strange piece of code in UIParser.createWidget() around line 147:
>
>      parent = self.stack.topwidget
>      if isinstance(parent, (QtGui.QToolBox, QtGui.QTabWidget,
>                             QtGui.QStackedWidget)):
>          parent = None
>          #^^^^^^^^^^^^^^here is the strange point
>
>      self.stack.push(self.setupObject(widgetClass(elem), parent, elem))
>                      #^^^^^^^^^^^^^^^ this calls my code
>
> So in this case, the parent object is deliberately set to None when
> the QTabWidget's page gets created!
>
> What's the reason of such behavior?
>
> Please note that if i replace the "parent = None" line with a "pass"
> all goes on fine an the form shown without any problems, with the
> right page shown and the tab swiching working fine.

I can't answer the question as I didn't write the original code.

Phil
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to