I would disable button after other button_click event and enable again after timer timeout. I tried with Timer and States with PropertyChanged, but it doesn't work.
How I can send a qml signal to reload/refresh the page?
When i click on id_button_add I would disable Id_button_edit and start a timer for 3 seconds. When the timer timeouts I enable already the id_button_edit.
Here is my code.
Qt Code:
import QtQuick 2.0 import QtQuick.Layouts 1.3 import "../items" import ch.example 1.0 Item { id: id_root z: 2 property bool prepare_delete: false property string button_edit_enable_state: "enabled" anchors.left: parent ? parent.left : undefined anchors.right: parent ? parent.right : undefined Connections { target: id_root.ListView.view onCurrentIndexChanged: { prepare_delete = false } } function update_remove_enable() { id_button_remove.button_enabled = ui_resident_model.sourceModel.rowCount() > 1 } Component.onCompleted: { ui_resident_model.sourceModel.onRowsInserted.connect(update_remove_enable) ui_resident_model.sourceModel.onRowsRemoved.connect(update_remove_enable) update_remove_enable() } Rectangle { anchors.fill: parent color: "transparent" border { color: touchpanel_style.foreground_color width: touchpanel_style.line_width } } RowLayout { anchors.left: parent.left anchors.margins: touchpanel_style.margin anchors.verticalCenter: parent.verticalCenter . . . . } RowLayout { id: id_content anchors.right: parent.right anchors.margins: touchpanel_style.margin anchors.verticalCenter: parent.verticalCenter state: button_edit_enable_state states: [ State { name: "enabled" PropertyChanges { target: id_button_edit; enabled: true } }, State { name: "disabled" PropertyChanges { target: id_button_edit; enabled: false } } ] Timer { id: serviceListItemTimer interval: 3000 running: false repeat: false onTriggered: { console.log("onTriggered") button_edit_enable_state = "enabled" } } IconButton { id: id_button_edit objectName: "button_edit" Layout.fillHeight: true width: height icon_factor: 1.35 icon_source: "../icons/edit.png" onButtonClick: { prepare_delete = false loader.source = "../service_menu/ResidentEdit.qml"; loader.item.onCancel.connect(cancel_edit) loader.item.onTimeout.connect(timeout) loader.item.model = id_root.ListView.view.currentItem.resident_model } function cancel_edit() { loader.source = "" } } IconButton { id: id_button_add objectName: "button_add" Layout.fillHeight: true width: height icon_factor: 1.35 icon_source: "../icons/resident_add.svg" onButtonClick: { console.log("btn_add") button_edit_enable_state = "disabled" serviceListItemTimer.start() //serviceListItemTimer.running = true var index = id_root.ListView.view.currentIndex; id_root.ListView.view.model.createItem(index); set_index(index); } } } }import QtQuick 2.0 import QtQuick.Layouts 1.3 import "../items" import ch.example 1.0 Item { id: id_root z: 2 property bool prepare_delete: false property string button_edit_enable_state: "enabled" anchors.left: parent ? parent.left : undefined anchors.right: parent ? parent.right : undefined Connections { target: id_root.ListView.view onCurrentIndexChanged: { prepare_delete = false } } function update_remove_enable() { id_button_remove.button_enabled = ui_resident_model.sourceModel.rowCount() > 1 } Component.onCompleted: { ui_resident_model.sourceModel.onRowsInserted.connect(update_remove_enable) ui_resident_model.sourceModel.onRowsRemoved.connect(update_remove_enable) update_remove_enable() } Rectangle { anchors.fill: parent color: "transparent" border { color: touchpanel_style.foreground_color width: touchpanel_style.line_width } } RowLayout { anchors.left: parent.left anchors.margins: touchpanel_style.margin anchors.verticalCenter: parent.verticalCenter . . . . } RowLayout { id: id_content anchors.right: parent.right anchors.margins: touchpanel_style.margin anchors.verticalCenter: parent.verticalCenter state: button_edit_enable_state states: [ State { name: "enabled" PropertyChanges { target: id_button_edit; enabled: true } }, State { name: "disabled" PropertyChanges { target: id_button_edit; enabled: false } } ] Timer { id: serviceListItemTimer interval: 3000 running: false repeat: false onTriggered: { console.log("onTriggered") button_edit_enable_state = "enabled" } } IconButton { id: id_button_edit objectName: "button_edit" Layout.fillHeight: true width: height icon_factor: 1.35 icon_source: "../icons/edit.png" onButtonClick: { prepare_delete = false loader.source = "../service_menu/ResidentEdit.qml"; loader.item.onCancel.connect(cancel_edit) loader.item.onTimeout.connect(timeout) loader.item.model = id_root.ListView.view.currentItem.resident_model } function cancel_edit() { loader.source = "" } } IconButton { id: id_button_add objectName: "button_add" Layout.fillHeight: true width: height icon_factor: 1.35 icon_source: "../icons/resident_add.svg" onButtonClick: { console.log("btn_add") button_edit_enable_state = "disabled" serviceListItemTimer.start() //serviceListItemTimer.running = true var index = id_root.ListView.view.currentIndex; id_root.ListView.view.model.createItem(index); set_index(index); } } } }To copy to clipboard, switch view to plain text mode
I found a solution --> bind qml property with cpp model and emit also in cpp module valueChanged() signal
see http://imaginativethinking.ca/bi-dir...ding-qt-quick/
Bookmarks