Results 1 to 7 of 7

Thread: How to draw two rectangles with QtQuick?

  1. #1
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default How to draw two rectangles with QtQuick?

    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Rectangle
    4. {
    5. id: sas
    6. width: 200
    7. height: 100
    8. color: "red"
    9.  
    10. Text
    11. {
    12. anchors.centerIn: parent
    13. text: "Hello, World!"
    14. }
    15. }
    16.  
    17. Rectangle
    18. {
    19. id: sasas
    20. width: 200
    21. height: 100
    22. color: "red"
    23.  
    24. Text
    25. {
    26. anchors.centerIn: parent
    27. text: "Hello,fdsfdsf!"
    28. }
    29. }
    To copy to clipboard, switch view to plain text mode 


    This, when run with qmlviewer, says:

    Qt Code:
    1. Syntax error Rectangle {
    2. ^
    To copy to clipboard, switch view to plain text mode 

    What's the way out?

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to draw two rectangles with QtQuick?

    Have a parent Rectangle.

    You can have only one top item per qml...

    So do something like -
    Qt Code:
    1. Rectangle
    2. {
    3.  
    4. Rect1
    5. {}
    6. Rect2
    7. {}
    8. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: How to draw two rectangles with QtQuick?

    It can be an Item instead of Rectangle if it is to remain transparent.
    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.


  4. #4
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: How to draw two rectangles with QtQuick?

    If I put those two rectangles in a row, it "does" work.
    I wish to understand why:
    Qt Code:
    1. Row
    2. {
    3. Rectangle {...}
    4. Rectangle {...}
    5. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: How to draw two rectangles with QtQuick?

    Because there is one top-level item then.
    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.


  6. #6
    Join Date
    Apr 2011
    Posts
    231
    Thanks
    141
    Thanked 6 Times in 5 Posts

    Default Re: How to draw two rectangles with QtQuick?

    Is Row considered to be an item?

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

    Default Re: How to draw two rectangles with QtQuick?

    Yes, of course.
    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. Drawing rectangles in QT
    By andreahmed in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2012, 20:08
  2. Replies: 0
    Last Post: 14th November 2010, 14:36
  3. Replies: 1
    Last Post: 9th August 2010, 20:44
  4. editable rectangles
    By parmar ranjit in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2008, 10:59
  5. Rendering rectangles speed issue
    By macbeth in forum Qt Programming
    Replies: 11
    Last Post: 15th March 2007, 02:30

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.