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. [QML/Qt 6.2.4 C++ Model] Required properties bindings and contentItem model
Forum Updated to NodeBB v4.3 + New Features

[QML/Qt 6.2.4 C++ Model] Required properties bindings and contentItem model

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 221 Views
  • 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.
  • N Offline
    N Offline
    nico88desmo
    wrote on 10 Dec 2023, 22:43 last edited by
    #1

    Dear all,

    I'd like using a C++ model and show its data in two columns:

    1. Left column (list): ListView where, for each row, I put a Title
    2. Right column (detail): a set of different QML components where, for each component, I show more model data in details

    I'm using roles in the C++ model and, for each role, in the delegate item of the ListView I use required properties in order to create a binding

    The target is the follow: modify items on 'right column' and 'send' updated data to model.

    I follow this idea (even if I don't know if it is correct): when I change currentItem on left column, I send its model (which has C++ roles bound to required properties) to right column and, for each Component, when I change data, I send updated data to model.

    This is the (possible) implementation:

    // left column
    ListView {
       ...
       model: controller.sampleModel  // <-- C++ model
       delegate: CustomDelegate {
          required property var model
          required property int index
          required property string title
          required property int data1
          required property int data2
          ...
          text: title
          ...
       }
       onCurrentItemChanged: { //<-- send model to right column (model with required properties and theirs bindings)
          if (rightColumn.model !== currentItem.model)
             rightColumn.model = currentItem.model  // <--- use of currentItem
       }
    }
    
    // right column
    ColumnLayout {
       id: rightColumn
       property var model
       TextField { text: model.title; onTextChanged: model.title = text }
       TextField { text: model.data1 }
       TextField { text: model.data2 }
    }
    

    My questions are:

    1. is this feasible or does exist any drawback?
    2. using currentItem, theoricaly it has always correctly usable (even if that item goes out of visible items), right? so also in this case, things should work

    In this way, viewing and changing model data from 'Right column' becomes very easy and clean; what do you think?

    Thanks in advance!
    Nicola

    1 Reply Last reply
    0

    1/1

    10 Dec 2023, 22:43

    • Login

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