summaryrefslogtreecommitdiffstats
path: root/tests/QtGui/bug_1006.py
blob: 33afdfb965d2dfc4db8ff586535fdaadd9900518 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import unittest
import weakref
from PySide.QtCore import Qt
from PySide.QtGui import QDialog, QLabel, QGridLayout

from helper import TimedQApplication

class LabelWindow(QDialog):
    def __init__(self, parent):
        super(LabelWindow, self).__init__(parent)

        self.test_layout = QGridLayout()
        label = QLabel("Label")
        self.test_layout.addWidget(label, 0, 0)
        self.setLayout(self.test_layout)
        self._destroyCalled = False


    def replace(self):
        old_item = self.test_layout.itemAtPosition(0, 0)
        ref = weakref.ref(old_item, self._destroyed)
        old_label = old_item.widget()
        del old_item

        self.test_layout.removeWidget(old_label)
        label = QLabel("Label New")
        old_label.deleteLater()
        label.setAlignment(Qt.AlignCenter)
        self.test_layout.addWidget(label, 0, 0)

    def _destroyed(self, obj):
        self._destroyCalled = True

class TestBug1006 (TimedQApplication):

    def testLayoutItemLifeTime(self):
        window = LabelWindow(None)
        window.replace()
        self.assertTrue(window._destroyCalled)
        self.app.exec_()

if __name__ == "__main__":
    unittest.main()