在 QML 中,很容易编写创建属性绑定(bind),例如:
Rectangle {
width: parent.width
}
是否也可以在 C++ 中执行此操作?
最佳答案
在 Qt 中,一些 QObject
有特定的 properties可以使用信号和槽“绑定(bind)”:
auto *someWidget = QPushButton(/* ... */);
auto *otherRelatedWidget = QLabel( /* ... */ );
// windowTitle is a property for both QWidgets
QObject::connect(someWidget, &QWidget::windowTitleChanged,
otherRelatedWidget, &QWidget::setWindowTitle);
除此之外,您仍然可以连接其他信号和槽,即使它们没有关联到属性。
我必须指出,这样做没有语法糖。查看properties documentation了解更多信息。
关于c++ - 如何在 Qt/C++ 中创建属性绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32842557/