Results 1 to 10 of 10

Thread: Cant access alias from Item

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cant access alias from Item

    wysota, thank you very much for the help. It worked.

    I am posting here a minimal example just to exemplify for who needs.

    MainForm.ui.qml
    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.2
    3. import QtQuick.Layouts 1.1
    4.  
    5. Rectangle {
    6. id: mainContainer
    7.  
    8. property alias mainContainerA: mainContainer
    9. property alias buttonA: button
    10. property alias listviewA: listView
    11. property alias rect1A: rect1
    12. property alias rect2A: rect2
    13.  
    14. width: 600
    15. height: 600
    16.  
    17. Button {
    18. id: button
    19.  
    20. anchors.top: parent.top
    21.  
    22. text: "Insert value"
    23.  
    24. height: parent.height * 0.1
    25. width: parent.width
    26. }
    27.  
    28. ListView {
    29. id: listView
    30.  
    31. anchors.top: button.bottom
    32.  
    33. clip: true
    34.  
    35. height: parent.height * 0.5
    36. width: parent.width
    37. }
    38.  
    39. Rectangle {
    40. id: rect1
    41.  
    42. visible: true
    43.  
    44. anchors.top: listView.bottom
    45.  
    46. width: parent.width
    47. height: parent.height * 0.4
    48.  
    49. color: "blue"
    50. }
    51.  
    52. Rectangle {
    53. id: rect2
    54.  
    55. visible: false
    56.  
    57. anchors.top: listView.bottom
    58.  
    59. width: parent.width
    60. height: parent.height * 0.4
    61.  
    62. color: "red"
    63. }
    64. }
    To copy to clipboard, switch view to plain text mode 

    main.qml
    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Window 2.2
    3.  
    4. Window {
    5. visible: true
    6.  
    7. width: 600
    8. height: 600
    9.  
    10. MainForm {
    11. anchors.fill: parent
    12.  
    13. listviewA.model: modelM
    14. listviewA.delegate: delegateM.delegateComponent
    15.  
    16. buttonA.onClicked: {
    17. modelM.append({valor: 100, tipo: 2, tipoIndex: 3});
    18. }
    19.  
    20. rect1A.visible: delegateM.rect1Visible
    21. rect2A.visible: delegateM.rect2Visible
    22. }
    23.  
    24. Delegate {
    25. id: delegateM
    26. }
    27.  
    28. Model {
    29. id: modelM
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 

    Delegate.qml
    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.2
    3. import QtQuick.Window 2.2
    4.  
    5. Item {
    6. id: delegateItem
    7.  
    8. property Component delegateComponent: delegateComponent
    9. property bool rect1Visible: true
    10. property bool rect2Visible: false
    11.  
    12. Component {
    13. id: delegateComponent
    14.  
    15. Row {
    16. height: 53
    17.  
    18. Column {
    19. width: 600 * 0.96 / 8 * 6
    20. //width: Screen.width * 0.96 / 8 * 6
    21.  
    22.  
    23. Text {
    24. text: "<strong>" + "Valor: " + valor + "</strong>"
    25. font.pixelSize: 16
    26. }
    27. Text {
    28. text: "Tipo: " + tipo
    29. font.pixelSize: 16
    30. }
    31. }
    32.  
    33. Column {
    34. width: 600 * 0.96 / 8
    35. //width: Screen.width * 0.96 / 8
    36.  
    37. Rectangle {
    38. color: "grey"
    39. width: 50
    40. height: 50
    41. MouseArea {
    42. id: editMouseArea
    43.  
    44. anchors.fill: parent
    45.  
    46. onClicked:
    47. {
    48. rect1Visible = true;
    49. rect2Visible = false;
    50. }
    51. }
    52. }
    53.  
    54. }
    55.  
    56. Column {
    57. width: 600 * 0.96 / 8
    58. //width: Screen.width * 0.96 / 8
    59.  
    60. Rectangle {
    61. color: "darkred"
    62. width: 50
    63. height: 50
    64. MouseArea {
    65. id: removeMouseArea
    66.  
    67. anchors.fill: parent
    68.  
    69. onClicked:
    70. {
    71. rect1Visible = false;
    72. rect2Visible = true;
    73. }
    74. }
    75. }
    76. }
    77. }
    78. }
    79. }
    To copy to clipboard, switch view to plain text mode 

    Model.qml
    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. ListModel {
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cant access alias from Item

    Sorry to criticise your code but you should really avoid exposing all those items as aliases.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Cant access alias from Item

    No problem. I am new in QML and thats is the best way to learn more. Your criticals and suggestions are welcome.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cant access alias from Item

    Exposing those items means you want to be able to access any property of each of them from anywhere. In that case you should probably either put all the code in one document or decide which set of properties to expose from each object and alias just that. Alternatively use components to decide about an internal item from outside of its parent item, just like views do with delegates.

    Something along the lines of:

    javascript Code:
    1. Item {
    2. id: root
    3.  
    4. property Component rect1Component: Rectangle { /* default rec1 */ ... }
    5.  
    6. Loader {
    7. id: rect1
    8. sourceComponent: rect1Component
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Then you can program that item from a document which instantiates it by assigning a different component to rect1Component.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 16
    Last Post: 12th October 2015, 16:02
  2. Replies: 1
    Last Post: 9th May 2013, 15:53
  3. Replies: 2
    Last Post: 3rd February 2011, 10:07
  4. Replies: 2
    Last Post: 24th May 2009, 10:27
  5. qresource file alias problem with svg
    By giotto in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2008, 15:59

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
  •  
Qt is a trademark of The Qt Company.