Results 1 to 2 of 2

Thread: QML disable button after other button_click event and enable again after timer timeou

  1. #1
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default QML disable button after other button_click event and enable again after timer timeou

    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:
    1. import QtQuick 2.0
    2. import QtQuick.Layouts 1.3
    3.  
    4. import "../items"
    5. import ch.example 1.0
    6.  
    7. Item {
    8. id: id_root
    9. z: 2
    10.  
    11. property bool prepare_delete: false
    12. property string button_edit_enable_state: "enabled"
    13.  
    14. anchors.left: parent ? parent.left : undefined
    15. anchors.right: parent ? parent.right : undefined
    16.  
    17. Connections {
    18. target: id_root.ListView.view
    19. onCurrentIndexChanged: {
    20. prepare_delete = false
    21. }
    22. }
    23.  
    24. function update_remove_enable() {
    25. id_button_remove.button_enabled = ui_resident_model.sourceModel.rowCount() > 1
    26. }
    27.  
    28. Component.onCompleted: {
    29. ui_resident_model.sourceModel.onRowsInserted.connect(update_remove_enable)
    30. ui_resident_model.sourceModel.onRowsRemoved.connect(update_remove_enable)
    31. update_remove_enable()
    32. }
    33.  
    34. Rectangle {
    35. anchors.fill: parent
    36.  
    37. color: "transparent"
    38. border {
    39. color: touchpanel_style.foreground_color
    40. width: touchpanel_style.line_width
    41. }
    42. }
    43.  
    44. RowLayout {
    45. anchors.left: parent.left
    46. anchors.margins: touchpanel_style.margin
    47. anchors.verticalCenter: parent.verticalCenter
    48.  
    49. .
    50. .
    51. .
    52. .
    53. }
    54.  
    55. RowLayout {
    56. id: id_content
    57. anchors.right: parent.right
    58. anchors.margins: touchpanel_style.margin
    59. anchors.verticalCenter: parent.verticalCenter
    60.  
    61. state: button_edit_enable_state
    62.  
    63. states: [
    64. State {
    65. name: "enabled"
    66. PropertyChanges { target: id_button_edit; enabled: true }
    67. },
    68. State {
    69. name: "disabled"
    70. PropertyChanges { target: id_button_edit; enabled: false }
    71. }
    72. ]
    73.  
    74. Timer {
    75. id: serviceListItemTimer
    76. interval: 3000
    77. running: false
    78. repeat: false
    79. onTriggered: {
    80. console.log("onTriggered")
    81. button_edit_enable_state = "enabled"
    82. }
    83. }
    84.  
    85. IconButton {
    86. id: id_button_edit
    87. objectName: "button_edit"
    88. Layout.fillHeight: true
    89. width: height
    90.  
    91. icon_factor: 1.35
    92. icon_source: "../icons/edit.png"
    93.  
    94. onButtonClick: {
    95. prepare_delete = false
    96. loader.source = "../service_menu/ResidentEdit.qml";
    97. loader.item.onCancel.connect(cancel_edit)
    98. loader.item.onTimeout.connect(timeout)
    99. loader.item.model = id_root.ListView.view.currentItem.resident_model
    100. }
    101.  
    102. function cancel_edit() {
    103. loader.source = ""
    104. }
    105. }
    106.  
    107. IconButton {
    108. id: id_button_add
    109. objectName: "button_add"
    110. Layout.fillHeight: true
    111. width: height
    112.  
    113. icon_factor: 1.35
    114. icon_source: "../icons/resident_add.svg"
    115.  
    116. onButtonClick: {
    117. console.log("btn_add")
    118. button_edit_enable_state = "disabled"
    119. serviceListItemTimer.start()
    120. //serviceListItemTimer.running = true
    121. var index = id_root.ListView.view.currentIndex;
    122. id_root.ListView.view.model.createItem(index);
    123. set_index(index);
    124. }
    125. }
    126. }
    127. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: QML disable button after other button_click event and enable again after timer ti

    Quote Originally Posted by Oxid2178 View Post
    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:
    1. import QtQuick 2.0
    2. import QtQuick.Layouts 1.3
    3.  
    4. import "../items"
    5. import ch.example 1.0
    6.  
    7. Item {
    8. id: id_root
    9. z: 2
    10.  
    11. property bool prepare_delete: false
    12. property string button_edit_enable_state: "enabled"
    13.  
    14. anchors.left: parent ? parent.left : undefined
    15. anchors.right: parent ? parent.right : undefined
    16.  
    17. Connections {
    18. target: id_root.ListView.view
    19. onCurrentIndexChanged: {
    20. prepare_delete = false
    21. }
    22. }
    23.  
    24. function update_remove_enable() {
    25. id_button_remove.button_enabled = ui_resident_model.sourceModel.rowCount() > 1
    26. }
    27.  
    28. Component.onCompleted: {
    29. ui_resident_model.sourceModel.onRowsInserted.connect(update_remove_enable)
    30. ui_resident_model.sourceModel.onRowsRemoved.connect(update_remove_enable)
    31. update_remove_enable()
    32. }
    33.  
    34. Rectangle {
    35. anchors.fill: parent
    36.  
    37. color: "transparent"
    38. border {
    39. color: touchpanel_style.foreground_color
    40. width: touchpanel_style.line_width
    41. }
    42. }
    43.  
    44. RowLayout {
    45. anchors.left: parent.left
    46. anchors.margins: touchpanel_style.margin
    47. anchors.verticalCenter: parent.verticalCenter
    48.  
    49. .
    50. .
    51. .
    52. .
    53. }
    54.  
    55. RowLayout {
    56. id: id_content
    57. anchors.right: parent.right
    58. anchors.margins: touchpanel_style.margin
    59. anchors.verticalCenter: parent.verticalCenter
    60.  
    61. state: button_edit_enable_state
    62.  
    63. states: [
    64. State {
    65. name: "enabled"
    66. PropertyChanges { target: id_button_edit; enabled: true }
    67. },
    68. State {
    69. name: "disabled"
    70. PropertyChanges { target: id_button_edit; enabled: false }
    71. }
    72. ]
    73.  
    74. Timer {
    75. id: serviceListItemTimer
    76. interval: 3000
    77. running: false
    78. repeat: false
    79. onTriggered: {
    80. console.log("onTriggered")
    81. button_edit_enable_state = "enabled"
    82. }
    83. }
    84.  
    85. IconButton {
    86. id: id_button_edit
    87. objectName: "button_edit"
    88. Layout.fillHeight: true
    89. width: height
    90.  
    91. icon_factor: 1.35
    92. icon_source: "../icons/edit.png"
    93.  
    94. onButtonClick: {
    95. prepare_delete = false
    96. loader.source = "../service_menu/ResidentEdit.qml";
    97. loader.item.onCancel.connect(cancel_edit)
    98. loader.item.onTimeout.connect(timeout)
    99. loader.item.model = id_root.ListView.view.currentItem.resident_model
    100. }
    101.  
    102. function cancel_edit() {
    103. loader.source = ""
    104. }
    105. }
    106.  
    107. IconButton {
    108. id: id_button_add
    109. objectName: "button_add"
    110. Layout.fillHeight: true
    111. width: height
    112.  
    113. icon_factor: 1.35
    114. icon_source: "../icons/resident_add.svg"
    115.  
    116. onButtonClick: {
    117. console.log("btn_add")
    118. button_edit_enable_state = "disabled"
    119. serviceListItemTimer.start()
    120. //serviceListItemTimer.running = true
    121. var index = id_root.ListView.view.currentIndex;
    122. id_root.ListView.view.model.createItem(index);
    123. set_index(index);
    124. }
    125. }
    126. }
    127. }
    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/

Similar Threads

  1. Replies: 6
    Last Post: 25th January 2019, 12:01
  2. Enable and Disable Close (X)
    By anh5kor in forum Newbie
    Replies: 2
    Last Post: 25th March 2015, 07:45
  3. Replies: 4
    Last Post: 14th February 2014, 18:57
  4. Timer event & paint event, priority
    By Teuniz in forum Qt Programming
    Replies: 0
    Last Post: 2nd February 2010, 14:33
  5. how to enable a timer in a non-gui thread?
    By zeopha in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2008, 10:29

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.