summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-11-27 15:36:24 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-11-28 10:10:43 +0000
commita5d4a71d32d1b2a095119351a0935c49f3ac0a50 (patch)
treee1de37493a9d0394500c6ab5c2976d7959e42229
parent0a70c8485771ae8cc62faaa775b1db2a5dbd95ef (diff)
QApplication::setStyle ownership transfer
Due to the nature of the qApp singleton, it was not enough to add the refcount of the style via the typesystem, as usual. An additional step of getting a reference to the qApp to set the parent of the style was required. A test case was included. Change-Id: I5e60983e961e7d3d310b1e1c2f6f9b80ee095308 Fixes: PYSIDE-861 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
-rw-r--r--sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml3
-rw-r--r--sources/pyside2/PySide2/glue/qtwidgets.cpp8
-rw-r--r--sources/pyside2/tests/QtWidgets/qstyle_test.py8
3 files changed, 19 insertions, 0 deletions
diff --git a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
index 8d732d90..c7fae8d7 100644
--- a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
+++ b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
@@ -2956,6 +2956,9 @@
<add-function signature="QApplication()">
<inject-code file="../glue/qtwidgets.cpp" snippet="qapplication-2"/>
</add-function>
+ <modify-function signature="setStyle(QStyle*)">
+ <inject-code class="target" position="end" file="../glue/qtwidgets.cpp" snippet="qapplication-setStyle"/>
+ </modify-function>
<modify-function signature="exec()" rename="exec_" allow-thread="yes"/>
<inject-code class="native" file="glue/qapplication_init.cpp" position="beginning"/>
</object-type>
diff --git a/sources/pyside2/PySide2/glue/qtwidgets.cpp b/sources/pyside2/PySide2/glue/qtwidgets.cpp
index f0e446f6..02e74c99 100644
--- a/sources/pyside2/PySide2/glue/qtwidgets.cpp
+++ b/sources/pyside2/PySide2/glue/qtwidgets.cpp
@@ -266,6 +266,14 @@ if (myStyle && qApp) {
}
// @snippet qwidget-style
+// @snippet qapplication-setStyle
+if (qApp) {
+ Shiboken::AutoDecRef pyApp(%CONVERTTOPYTHON[QApplication*](qApp));
+ Shiboken::Object::setParent(pyApp, %PYARG_1);
+ Shiboken::Object::releaseOwnership(%PYARG_1);
+}
+// @snippet qapplication-setStyle
+
// @snippet qwidget-setlayout
qwidgetSetLayout(%CPPSELF, %1);
// %FUNCTION_NAME() - disable generation of function call.
diff --git a/sources/pyside2/tests/QtWidgets/qstyle_test.py b/sources/pyside2/tests/QtWidgets/qstyle_test.py
index eb2a73d2..1dcce273 100644
--- a/sources/pyside2/tests/QtWidgets/qstyle_test.py
+++ b/sources/pyside2/tests/QtWidgets/qstyle_test.py
@@ -26,6 +26,7 @@
##
#############################################################################
+import sys
import unittest
from helper import UsesQApplication
@@ -78,6 +79,13 @@ class SetStyleTest(UsesQApplication):
QApplication.instance().processEvents()
self.assertTrue(proxyStyle.polished > 0)
+ def testSetStyleOwnership(self):
+ style = QStyleFactory.create(QStyleFactory.keys()[0])
+ self.assertEqual(sys.getrefcount(style), 2)
+ QApplication.instance().setStyle(style)
+ self.assertEqual(sys.getrefcount(style), 3)
+
+
if __name__ == '__main__':
unittest.main()