Fixed QWidget setLayout rules.
Reviewer: Hugo Parente Lima <hugo.pl@gmail.com>
Luciano Wolf <luciano.wolf@openbossa.org>
This commit is contained in:
parent
73fea93181
commit
7f4e85f650
1 changed files with 23 additions and 7 deletions
|
|
@ -17,12 +17,14 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout)
|
||||||
{
|
{
|
||||||
QLayoutItem *item = layout->itemAt(i);
|
QLayoutItem *item = layout->itemAt(i);
|
||||||
QWidget *w = item->widget();
|
QWidget *w = item->widget();
|
||||||
|
|
||||||
if (w)
|
if (w)
|
||||||
{
|
{
|
||||||
|
QWidget* pw = w->parentWidget();
|
||||||
|
if (pw != parent) {
|
||||||
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w));
|
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QWidget*>::toPython(w));
|
||||||
Shiboken::setParent(pyParent, pyChild);
|
Shiboken::setParent(pyParent, pyChild);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QLayout *l = item->layout();
|
QLayout *l = item->layout();
|
||||||
|
|
@ -33,7 +35,6 @@ qwidgetReparentLayout(QWidget *parent, QLayout *layout)
|
||||||
|
|
||||||
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QLayout*>::toPython(layout));
|
Shiboken::AutoDecRef pyChild(Shiboken::Converter<QLayout*>::toPython(layout));
|
||||||
Shiboken::setParent(pyParent, pyChild);
|
Shiboken::setParent(pyParent, pyChild);
|
||||||
|
|
||||||
//remove previous references
|
//remove previous references
|
||||||
Shiboken::keepReference(reinterpret_cast<Shiboken::SbkBaseWrapper*>(pyChild.object()), qPrintable(retrieveObjectName(pyChild)), Py_None);
|
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
|
static inline void
|
||||||
qwidgetSetLayout(QWidget *self, QLayout *layout)
|
qwidgetSetLayout(QWidget *self, QLayout *layout)
|
||||||
{
|
{
|
||||||
if (self->layout())
|
if (!layout || self->layout())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
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);
|
qwidgetReparentLayout(self, layout);
|
||||||
self->setLayout(layout);
|
self->setLayout(layout);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue