Results 1 to 11 of 11

Thread: Property alias - make visible rectangle in other qml file

  1. #1
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Property alias - make visible rectangle in other qml file

    I have looked at the following site, and I am trying to get it working: http://stackoverflow.com/questions/2...other-qml-file
    I did not get it working with this code:


    ToClick.qml:
    Qt Code:
    1. ToChange
    2. {
    3. id:luncherList
    4. }
    5. (in mousearea:)
    6. onClicked:
    7. {
    8. luncherList.callUrl = 'T';
    9. }
    To copy to clipboard, switch view to plain text mode 


    ToChange.qml:
    Qt Code:
    1. visible: false
    2. property alias callUrl: item1.visible
    3. onCallUrlChanged:
    4. {
    5. item1.visible = (callUrl != 'T' ? false : true);
    6. }
    To copy to clipboard, switch view to plain text mode 

    What do I have to do to make visible the rectangle of item1 in ToChange.qml on click of ToClick.qml?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Property alias - make visible rectangle in other qml file

    That makes no sense.

    ToChange.qml defines "callUrl" as an alias for "visible" of another element, which is a boolean property.
    You can't assign 'T' to a boolean.

    If ToClick needs to change the visible property of item1 inside ToChange, then just assign the value you need (true or false) to the alias property.
    You might want to use a different name then callUrl, since it is a boolean, not an url

    Cheers,
    _

  3. #3
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Property alias - make visible rectangle in other qml file

    Thanks for the explanation. Now I also want to change color of the rectangle of item1 in ToChange.qml on click of ToClick.qml. I tried but how to get it working?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Property alias - make visible rectangle in other qml file

    Assuming "item1" is your rectangle, just make an alias property for its "color" property.

    Cheers,
    _

  5. #5
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Property alias - make visible rectangle in other qml file

    No, item1 is the Item, in which a rectangle is placed called circle. So how do I change the color of this circle from clicking on a rectangle of the other file?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Property alias - make visible rectangle in other qml file

    Give the rectange an id, create an alias property for the rectangle's color using that id.

    Cheers,
    _

  7. #7
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Property alias - make visible rectangle in other qml file

    This is what I have, but it is not changing color of the rectangle called circle:

    ToClick.qml:
    Qt Code:
    1. onClicked:
    2. {
    3. luncherList.colorRef = "blue";
    4. }
    To copy to clipboard, switch view to plain text mode 

    ToChange.qml:
    Qt Code:
    1. property alias colorRef: circle.colorUrl
    2.  
    3. Rectangle {
    4. id: circle
    5. property color colorUrl
    6. onColorUrlChanged:
    7. {
    8. console.log("hello3");
    9. circle.colorUrl = "blue"
    10. }
    To copy to clipboard, switch view to plain text mode 

    Can you tell me what I am doing wrong?

  8. #8
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Change color of rectangle in Page2 onPressed of Page1

    When the rectangle (id: circle) in Page2 is pressed, its color changes because the State says so. But how can I change the color of the rectangle in Page2 from onPressed in Page1?

    Page1.qml:
    MouseArea {
    id: myma
    //...

    Page2.qml:
    Qt Code:
    1. states: State {
    2. name: "resized"; when: mymousearea.pressed
    3. PropertyChanges { target: circle; color: "blue" }
    4. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change color of rectangle in Page2 onPressed of Page1

    If you have an instance of Page2 inside Page1, then you can set any property of that Page2 instance.

    If any such property is the binding of the inner rectangle's color property or an alias to that then you will change that inner rectangle's color.

    Cheers,
    _

  10. #10
    Join Date
    Aug 2016
    Posts
    36
    Qt products
    Qt4
    Platforms
    Windows

    Default Change color with property alias of clickable circles

    When the colorUr is changed from another file, the color of the circle must change. A you can see, the circles are placed on the mouseArea by clicking on it. The console says "hello6", but the color of the circle is not changed. I do not get it working. Please help.


    Qt Code:
    1. property alias colorUr: myma.colorMy2
    2.  
    3. Rectangle {
    4. id: circle
    5.  
    6. MouseArea {
    7. id: myma
    8. anchors.fill: parent
    9. property color colorMy2
    10. onColorMy2Changed:
    11. {
    12. console.log("hello6");
    13. circle.color = "green"
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Change color with property alias of clickable circles

    I've merged your various duplicated threads since it is pointless to answer the same questions again and again.

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 24th June 2016, 05:32
  2. QgraphicsView rubber band selection rectangle not visible
    By tarunrajsingh in forum Qt Programming
    Replies: 1
    Last Post: 3rd April 2013, 17:44
  3. Replies: 2
    Last Post: 22nd December 2010, 15:58
  4. Make Grid of Rectangle
    By sagirahmed in forum Newbie
    Replies: 1
    Last Post: 8th October 2010, 07:59
  5. qresource file alias problem with svg
    By giotto in forum Qt Programming
    Replies: 2
    Last Post: 19th February 2008, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.