Hello All,

QML offers property binding, which is supremely useful. So, in a QML code like 
this

Item {
   id: oneItem
   width: anotherItem.width * 2
}

Whenever anotherItem’s width changes, oneItem’s width is recomputed. 

From what I have seen we don’t have a direct way to make this kind of thing 
happen in C++. We will have to explicitly connect to widthChanged() signal in 
anotherItem and update oneItem’s width. 

I run into situations where I have to show a slider’s value in a label for 
example. I would love it if we could write something like this:

QSlider *slider = ...
QLabel *label = ....
QObject::bind(slider, "value", label, "text”);

Sometimes, I want to alter the label’s text value based on slider’s current 
value. I would love it if we could write something like this:

QSlider *slider = ....
QLabel *label = ....
QObject::bind(slider, "value", label, "text", [](const QVariant &v) { return 
v.toInt()*2; });


For now, I have written my own PropertyBinder class as shown here: 
https://goo.gl/ejOIcF

It would be great if this feature is available in QtCore. I wasn’t sure where 
to make this suggestion, so I sent my email here.

Thanks,
Prashanth

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to