Setting Layout.fillWidth from C++

  • I have an odd case here. I have some domain objects that are maintained in C++ and the QML is a presentation for them. However, up until now, I could just write generic code to present them. But now, I need object-specific presentation.

    Since the logic and copious types are in C++, I'd like to create a form to edit these objects from within C++. With this, I actually have no problem:

    QQmlComponent GenericNew(

    auto * parent = GenericNew.create();

    for(auto const & field: object) {
    // Instantiates a field type-specific QQmlComponent

    The problem is that certain fields need to have Layout.fillWidth set to true because the form uses a grid layout. I cannot seem to figure out how to do this in C++ nor how to hook into it on the QML side to set it appropriately.

    Any suggestions?

  • Please tell me there is a better solution than this:

    /* in GenericNew.qml */
    onChildrenChanged: {
    for(var ii = 0; ii < children.length; ++ii) {
    if(children[ii]"attr-")>=0) {
    children[ii].Layout.fillWidth = true

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.