本文整理汇总了Python中AnyQt.QtCore.QObject.setProperty方法的典型用法代码示例。如果您正苦于以下问题:Python QObject.setProperty方法的具体用法?Python QObject.setProperty怎么用?Python QObject.setProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtCore.QObject
的用法示例。
在下文中一共展示了QObject.setProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_manager
# 需要导入模块: from AnyQt.QtCore import QObject [as 别名]
# 或者: from AnyQt.QtCore.QObject import setProperty [as 别名]
def test_manager(self):
source = QObject()
target = QObject()
manager = BindingManager(submitPolicy=BindingManager.ManualSubmit)
manager.bind((target, "target"), None).to((source, "source"))
tbind = DynamicPropertyBinding(target, "target_copy")
sbind = DynamicPropertyBinding(source, "source")
schanged = []
sbind.changed[object].connect(schanged.append)
manager.bind(tbind, None).to(sbind)
source.setProperty("source", 1)
self.assertEqual(len(schanged), 1)
self.assertEqual(target.property("target"), None)
manager.commit()
self.assertEqual(target.property("target"), 1)
self.assertEqual(target.property("target_copy"), 1)
source.setProperty("source", 2)
manager.setSubmitPolicy(BindingManager.AutoSubmit)
self.assertEqual(target.property("target"), 2)
self.assertEqual(target.property("target_copy"), 2)
示例2: test_expr
# 需要导入模块: from AnyQt.QtCore import QObject [as 别名]
# 或者: from AnyQt.QtCore.QObject import setProperty [as 别名]
def test_expr(self):
obj1 = QObject()
obj1.setProperty("value", 1)
obj1.setProperty("other", 2)
result = DynamicPropertyBinding(obj1, "result")
result.bindTo(
PropertyBindingExpr(
"value + other",
locals={"value": binding_for(obj1, "value"),
"other": binding_for(obj1, "other")}
)
)
expr = PropertyBindingExpr(
"True if value < 3 else False",
dict(value=DynamicPropertyBinding(obj1, "result"))
)
result_values = []
result.changed[object].connect(result_values.append)
expr_values = []
expr.changed[object].connect(expr_values.append)
self.assertEqual(result.get(), 3)
self.assertEqual(expr.get(), False)
obj1.setProperty("value", 0)
self.assertEqual(result_values[-1], 2)
self.assertEqual(expr_values[-1], True)
self.assertEqual(result.get(), 2)
self.assertEqual(expr.get(), True)
示例3: test_dyn
# 需要导入模块: from AnyQt.QtCore import QObject [as 别名]
# 或者: from AnyQt.QtCore.QObject import setProperty [as 别名]
def test_dyn(self):
obj = QObject()
changed = []
binding = DynamicPropertyBinding(obj, "test")
binding.changed[object].connect(changed.append)
self.assertIs(binding.get(), None)
obj.setProperty("test", 1)
self.assertEqual(binding.get(), 1)
self.assertEqual(len(changed), 1)
self.assertEqual(changed[-1], 1)
binding.set(2)
self.assertEqual(binding.get(), 2)
self.assertEqual(len(changed), 2)
self.assertEqual(changed[-1], 2)
target = QObject()
binding1 = DynamicPropertyBinding(target, "prop")
binding1.bindTo(binding)
self.assertEqual(binding1.get(), binding.get())
self.assertEqual(target.property("prop"), 2)
binding.set("a string")
self.assertEqual(binding1.get(), "a string")
self.assertEqual(binding1.get(), binding.get())
self.assertEqual(target.property("prop"), "a string")
binding1.unbind()
binding.set(1)
self.assertEqual(binding1.get(), "a string")
self.assertEqual(target.property("prop"), "a string")
self.assertEqual(binding.get(), 1)
self.assertEqual(obj.property("test"), 1)