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. VisualDataModel : 'model' property modification problem
Forum Updated to NodeBB v4.3 + New Features

VisualDataModel : 'model' property modification problem

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

    Hello everyone. I'm facing a problem with a VisualDataModel element.
    I want to modify the 'model' property of a VisualDataModel but the views using this visual data model are acting weirdly after the change.
    Is it a bug or is there a means to fix that behavior ?
    Thanks in advance for your answers.

    Here is a piece of code inspired by an example from Qt highlighting this problem (tested with Qt 4.8.0 and 4.8.4):

    @import QtQuick 1.1

    Rectangle {
    id: root
    color: "white"
    width: 400
    height: 150
    property bool mySwitch: true

    ListModel {
        id: myModel
        property string name: "model1"
        ListElement { display: "One" }
        ListElement { display: "Two" }
        ListElement { display: "Three" }
        ListElement { display: "Four" }
    }
    ListModel {
        id: myModel2
        property string name: "model2"
        ListElement { display: "Orange" }
        ListElement { display: "Apple" }
        ListElement { display: "Pear" }
        ListElement { display: "Banana" }
    }
    //![0]
    VisualDataModel {
        id: visualModel
        delegate: delegate
        model: root.mySwitch ? myModel : myModel2
    }
    
    ListView {
        width: 200; height:100
        model: visualModel.parts.list
    }
    GridView {
        x: 200; width: 200; height:100
        cellHeight: 50
        model: visualModel.parts.grid
    }
    //![0]
    
    Rectangle {
        color: "red"
        anchors.left: parent.left
        anchors.bottom: parent.bottom
        anchors.right: parent.right
        height: 50
        Text {
            anchors.centerIn: parent
            text: "Click Me !"
        }
    
        MouseArea {
            anchors.fill: parent
            onClicked: {
                root.mySwitch = !root.mySwitch;
                console.log(visualModel.model.name)
            }
        }
    }
    
    Component {
        id: delegate
        Package {
    
            Text { id: listDelegate; width: 200; height: 25; text: 'Empty'; Package.name: 'list' }
            Text { id: gridDelegate; width: 100; height: 50; text: 'Empty'; Package.name: 'grid' }
    
            Rectangle {
                id: wrapper
                width: 200; height: 25
                color: 'lightsteelblue'
    
                Text { text: display; anchors.centerIn: parent }
                MouseArea {
                    anchors.fill: parent
                    onClicked: {
                        if (wrapper.state == 'inList')
                            wrapper.state = 'inGrid';
                        else
                            wrapper.state = 'inList';
                    }
                }
    
                state: 'inList'
                states: [
                    State {
                        name: 'inList'
                        ParentChange { target: wrapper; parent: listDelegate }
                    },
                    State {
                        name: 'inGrid'
                        ParentChange {
                            target: wrapper; parent: gridDelegate
                            x: 0; y: 0; width: gridDelegate.width; height: gridDelegate.height
                        }
                    }
                ]
    
                transitions: [
                    Transition {
                        ParentAnimation {
                            NumberAnimation { properties: 'x,y,width,height'; duration: 300 }
                        }
                    }
                ]
            }
        }
    }
    

    }@

    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