Results 1 to 6 of 6

Thread: Change state on dynamic elements.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2013
    Posts
    5
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Change state on dynamic elements.

    Hello,
    In my program I add some buttons dynamically and I try to switch between two mode. The first mode is to move the buttons and the second to make it clickable and non-movable.
    My problem is I do not know how to change the state of an object dynamically added.

    Here my source code:

    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Controls 1.0
    3.  
    4. Rectangle {
    5. id: page
    6. width: 360
    7. height: 360
    8. Text {
    9. text: qsTr("Hello World")
    10. anchors.centerIn: parent
    11. }
    12.  
    13. Row {
    14. id: myRow
    15. anchors.fill: parent
    16. }
    17.  
    18. Component {
    19. id: myRectComp
    20.  
    21. Item {
    22. id: cell
    23. x: 0
    24. y: 30
    25.  
    26. Button {
    27. y: 30
    28. text: qsTr("My Butt")
    29.  
    30. MouseArea {
    31. id: contentMouseArea
    32. anchors.fill: parent
    33. drag.target: cell
    34.  
    35. // States to make an element in edition mode (movable) or not (clickable)
    36. states: [
    37. State {
    38. name: "movable"
    39. PropertyChanges { target: myRow; anchors.fill: parent }
    40. },
    41.  
    42. State {
    43. name: "clickable"
    44. PropertyChanges { target: myRow; anchors.fill: undefined }
    45. }
    46. ]
    47. }
    48. }
    49. }
    50. }
    51.  
    52. // Toolbar
    53. Row {
    54. id: toolbar
    55. anchors.fill: parent
    56.  
    57. Button {
    58. x: 0
    59. y: 0
    60. text: qsTr("Add Button")
    61. onClicked: {
    62. var rect = myRectComp.createObject(myRow)
    63. }
    64. }
    65.  
    66. Button {
    67. text: qsTr("Edition")
    68. checkable: true
    69. checked: true
    70. onClicked: contentMouseArea.state= 'clickable'
    71. }
    72. }
    73. }
    To copy to clipboard, switch view to plain text mode 

    Thank you for your help.

    EDIT: I found that on http://qt-project.org/doc/qt-4.7/qde...-59d951346a29:
    Also, note that while dynamically created objects may be used the same as other objects, they do not have an id in QML.
    So how can I do?
    Last edited by Binpix; 8th September 2013 at 22:40.

Similar Threads

  1. Change state property within a current state?
    By prophet0 in forum Qt Quick
    Replies: 1
    Last Post: 30th May 2012, 20:23
  2. Replies: 3
    Last Post: 26th July 2011, 20:11
  3. Replies: 1
    Last Post: 20th January 2011, 18:17
  4. Handling window state change
    By sudhansu in forum Qt Programming
    Replies: 0
    Last Post: 10th November 2010, 13:28
  5. Change position according to QCheckBox State
    By champ in forum Qt Programming
    Replies: 5
    Last Post: 6th June 2010, 19:37

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.