TableView and items [solved]



  • Hello,

    I wanted to know if it's possible to put something else than string or number into a TableView ? Like a checkbox or a ComboBox. I tried to search for examples but I can only fine ListView doing such things.

    I want a TableView to have a header and to sort the elements. It's like this :

    Player Name (String) - Connection Status (image) - Kick Player (Button)

    I tried also to create a rowDelegate with my differents items embedded in a Row, but it doesn't work either.

    Someone alreay tried this or has an idea on how to do such thing ?

    Thanks in advance !



  • Like this perhaps?

    @
    import QtQuick 2.1
    import QtQuick.Controls 1.0

    Rectangle {
    id: root
    width: 600
    height: 400
    TableView {
    model: ListModel {
    id: largeModel
    Component.onCompleted: {
    for (var i=0 ; i< 50 ; ++i)
    largeModel.append({"name":"Person "+i , "age": Math.round(Math.random()*100), "gender": Math.random()>0.5 ? "Male" : "Female"})
    }
    }
    anchors.fill: parent
    TableViewColumn {
    title: "Name"
    role: "name"
    }
    TableViewColumn {
    title: "status"
    role: "imagesource"
    width: 50
    delegate: Image {
    fillMode: Image.PreserveAspectFit
    source: "http://www.mricons.com/store/png/4092_1178_128_status_icon.png"
    }
    }
    TableViewColumn {
    title: ""
    delegate: Button {
    text: "Kick Player"
    onClicked: print("kicked player")
    }
    }
    }
    }
    @



  • Yeah that's it ! Ok I get it, i didn't think about putting the delegate directly into the TableViewColumn :) Thank for this !


Log in to reply
 

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