aboutsummaryrefslogtreecommitdiffstats
path: root/tests/QtDeclarative/bug_825.py
blob: d3c5519aa41426b509e0dc24016692b7334f212e (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
44
45
46
47
48
49
50
51
52
53
54
55
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtDeclarative import *

from helper import adjust_filename
import unittest

paintCalled = False

class MetaA(type):
    pass

class A(object):
    __metaclass__ = MetaA

MetaB = type(QDeclarativeItem)
B = QDeclarativeItem

class MetaC(MetaA, MetaB):
    pass

class C(A, B):
    __metaclass__ = MetaC

class Bug825 (C):

    def __init__(self, parent = None):
        QDeclarativeItem.__init__(self, parent)
        # need to disable this flag to draw inside a QDeclarativeItem
        self.setFlag(QGraphicsItem.ItemHasNoContents, False)

    def paint(self, painter, options, widget):
        global paintCalled
        pen = QPen(Qt.black, 2)
        painter.setPen(pen);
        painter.drawPie(self.boundingRect(), 0, 128);
        paintCalled = True

class TestBug825 (unittest.TestCase):
    def testIt(self):
        global paintCalled
        app = QApplication([])
        qmlRegisterType(Bug825, 'bugs', 1, 0, 'Bug825')
        self.assertRaises(TypeError, qmlRegisterType, A, 'bugs', 1, 0, 'A')

        view = QDeclarativeView()
        view.setSource(QUrl.fromLocalFile(adjust_filename('bug_825.qml', __file__)))
        view.show()
        QTimer.singleShot(250, view.close)
        app.exec_()
        self.assertTrue(paintCalled)


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