diff options
author | renatofilho <renato.filho@openbossa.org> | 2010-10-04 16:16:20 -0300 |
---|---|---|
committer | renatofilho <renato.filho@openbossa.org> | 2010-10-04 17:10:40 -0300 |
commit | 7f4e85f6501aa58623244303cdaf6e129c02af4d (patch) | |
tree | 02e91e77b7f9dd43cb3df205c937e7d659635892 /PySide | |
parent | 73fea931819ee1f6a32c50c9d67a9c292e69d45a (diff) | |
download | pyside-7f4e85f6501aa58623244303cdaf6e129c02af4d.tar.gz pyside-7f4e85f6501aa58623244303cdaf6e129c02af4d.tar.xz pyside-7f4e85f6501aa58623244303cdaf6e129c02af4d.zip |
Fixed QWidget setLayout rules.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'PySide')
-rw-r--r-- | PySide/QtGui/glue/qwidget_glue.h | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/PySide/QtGui/glue/qwidget_glue.h b/PySide/QtGui/glue/qwidget_glue.h index 9488522..6be6518 100644 --- a/PySide/QtGui/glue/qwidget_glue.h +++ b/PySide/QtGui/glue/qwidget_glue.h @@ -17,11 +17,13 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout) { QLayoutItem *item = layout->itemAt(i); QWidget *w = item->widget(); - if (w) { - Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w)); - Shiboken::setParent(pyParent, pyChild); + QWidget* pw = w->parentWidget(); + if (pw != parent) { + Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w)); + Shiboken::setParent(pyParent, pyChild); + } } else { @@ -33,7 +35,6 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout) Shiboken::AutoDecRef pyChild(Shiboken::Converter<QLayout*>::toPython(layout)); Shiboken::setParent(pyParent, pyChild); - //remove previous references Shiboken::keepReference(reinterpret_cast<Shiboken::SbkBaseWrapper*>(pyChild.object()), qPrintable(retrieveObjectName(pyChild)), Py_None); } @@ -41,9 +42,24 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout) static inline void qwidgetSetLayout(QWidget *self, QLayout *layout) { - if (self->layout()) + if (!layout || self->layout()) return; - qwidgetReparentLayout(self, layout); - self->setLayout(layout); + QObject* oldParent = layout->parent(); + if (oldParent && oldParent != self) { + if (oldParent->isWidgetType()) { + // remove old parent policy + Shiboken::AutoDecRef pyLayout(Shiboken::Converter<QLayout*>::toPython(layout)); + Shiboken::setParent(Py_None, pyLayout); + } else { + PyErr_Format(PyExc_RuntimeError, "QWidget::setLayout: Attempting to set QLayout \"%s\" on %s \"%s\", when the QLayout already has a parent", + qPrintable(layout->objectName()), self->metaObject()->className(), qPrintable(self->objectName())); + return; + } + } + + if (oldParent != self) { + qwidgetReparentLayout(self, layout); + self->setLayout(layout); + } } |