Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Setting Layout.fillWidth from C++
Forum Updated to NodeBB v4.3 + New Features

Setting Layout.fillWidth from C++

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 848 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sohail
    wrote on last edited by
    #1

    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(
    engine,
    genericNewQmlUrl
    );

    auto * parent = GenericNew.create();

    for(auto const & field: object) {
    // Instantiates a field type-specific QQmlComponent
    createSpecificQmlItemForField(field,parent);
    }
    @

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sohail
      wrote on last edited by
      #2

      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].objectName.search("attr-")>=0) {
      console.log(children[ii])
      children[ii].Layout.fillWidth = true
      }
      }
      }
      @

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved