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. Property MouseArea for each ListElement
Forum Updated to NodeBB v4.3 + New Features

Property MouseArea for each ListElement

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 760 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.
  • K Offline
    K Offline
    korsarqa
    wrote on last edited by
    #1

    Hello!
    I am a beginner user of Qt Project.

    Can't add a property for each element on ListModel.

    Code:
    @Rectangle {
    id: settings
    x: 0
    y: parent.height/10
    width: parent.width/43
    height: parent.height/10
    9
    color: "black"
    opacity: 0.5
    visible: false
    ListView {
    id: settingList
    x:0
    y:0
    width: parent.width
    height: parent.height
    model: ListModel {
    ListElement {
    name: "one"
    }
    ListElement {
    name: "two"
    }
    ListElement {
    name: "three"
    }
    ListElement {
    name: "four"
    }
    ListElement {
    name: "five"
    }
    }
    delegate: Item {
    width: settings.width
    height: 30
    Row {
    id: settingRow
    Rectangle {
    id: selectSetting
    width:settings.width
    height: 30
    color: "#00000000"
    Rectangle {
    y: 30
    width: settings.width
    height: 1
    color: "black"
    }
    Text {
    text: name
    font.bold: true
    anchors.verticalCenter: parent.verticalCenter
    }
    }
    }
    }
    }
    }@

    I want the property to be individualized for each list item.

    For example:

    Element "one"
    MouseArea {
    OnClicked: { function1}
    }

    Element "two"
    MouseArea {
    OnClicked: { function2 }
    }

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      You will have to do that in the delegate. Since delegate is an item you can provide it a MouseArea. For eg.
      @
      delegate: Item {
      MouseArea {
      anchors.fill: parent
      onClicked: console.log(index,model.name)
      }
      }
      @

      157

      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