def test_54(self): # issue #1029 (Crash for QBrush passed to setData) item = pya.QTreeWidgetItem() item.setBackground(0, pya.QBrush(pya.QColor(0xFF, 0xFF, 0x00))) self.assertEqual(item.background(0).color.red, 255) self.assertEqual(item.background(0).color.green, 255) self.assertEqual(item.background(0).color.blue, 0)
def test_41(self): # Lifetime management of objects/methods not using QObject.parent # QTreeWidgetItem (parent)/QTreeWidgetItem (child) # constructor with parent-like argument (supported by QObject parent/child relationship): tw = pya.QTreeWidgetItem() ti = pya.QTreeWidgetItem(tw) # that's not QObject.parent - this one still is 0 (not seen by RBA) self.assertEqual(ti.parent(), tw) self.assertEqual(tw.childCount(), 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.childCount(), 1) # the tree item belongs to the widget, hence it's destroyed with # the widget ti = tw.child(0) tw._destroy() # gives true, because tw owns ti too. self.assertEqual(ti._destroyed(), True) # The same works for insert too tw = pya.QTreeWidgetItem() ti = pya.QTreeWidgetItem() tw.insertChild(0, ti) self.assertEqual(tw.childCount(), 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.childCount(), 1) # the tree item belongs to the widget, hence it's destroyed with # the widget ti = tw.child(0) tw._destroy() # gives true, because tw owns ti self.assertEqual(ti._destroyed(), True) # And add: tw = pya.QTreeWidgetItem() ti = pya.QTreeWidgetItem() tw.addChild(ti) self.assertEqual(tw.childCount(), 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.childCount(), 1) # the tree item belongs to the widget, hence it's destroyed with # the widget ti = tw.child(0) tw._destroy() # gives true, because tw owns ti self.assertEqual(ti._destroyed(), True) # But the item is released when we take it and add: tw = pya.QTreeWidgetItem() ti = pya.QTreeWidgetItem() tw.addChild(ti) self.assertEqual(tw.childCount(), 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.childCount(), 1) ti = tw.takeChild(0) tw._destroy() # gives false, because we took ti and tw no longer owns it self.assertEqual(ti._destroyed(), False) # And we can destroy a child too tw = pya.QTreeWidgetItem() ti = pya.QTreeWidgetItem() tw.addChild(ti) self.assertEqual(tw.childCount(), 1) ti._destroy() self.assertEqual(tw.childCount(), 0)
def test_40(self): # Lifetime management of objects/methods not using QObject.parent # QTreeWidget (parent)/QTreeWidgetItem (child) # constructor with parent-like argument: tw = pya.QTreeWidget() ti = pya.QTreeWidgetItem(tw) # strange, but true: self.assertEqual(ti.parent(), None) self.assertEqual(tw.topLevelItemCount, 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.topLevelItemCount, 1) # the tree item belongs to the widget, hence it's destroyed with # the widget ti = tw.topLevelItem(0) tw._destroy() # gives true, because tw owns ti too. self.assertEqual(ti._destroyed(), True) # The same works for insert too tw = pya.QTreeWidget() ti = pya.QTreeWidgetItem() tw.insertTopLevelItem(0, ti) self.assertEqual(tw.topLevelItemCount, 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.topLevelItemCount, 1) # the tree item belongs to the widget, hence it's destroyed with # the widget ti = tw.topLevelItem(0) tw._destroy() # gives true, because tw owns ti self.assertEqual(ti._destroyed(), True) # And add: tw = pya.QTreeWidget() ti = pya.QTreeWidgetItem() tw.addTopLevelItem(ti) self.assertEqual(tw.topLevelItemCount, 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.topLevelItemCount, 1) # the tree item belongs to the widget, hence it's destroyed with # the widget ti = tw.topLevelItem(0) tw._destroy() # gives true, because tw owns ti self.assertEqual(ti._destroyed(), True) # But the item is released when we take it and add: tw = pya.QTreeWidget() ti = pya.QTreeWidgetItem() tw.addTopLevelItem(ti) self.assertEqual(tw.topLevelItemCount, 1) ti = None # gives 1, because the tree widget item is kept by # the tree widget: self.assertEqual(tw.topLevelItemCount, 1) ti = tw.takeTopLevelItem(0) tw._destroy() # gives false, because we took ti and tw no longer owns it self.assertEqual(ti._destroyed(), False) # And we can destroy a child too tw = pya.QTreeWidget() ti = pya.QTreeWidgetItem() tw.addTopLevelItem(ti) self.assertEqual(tw.topLevelItemCount, 1) ti._destroy() self.assertEqual(tw.topLevelItemCount, 0)