Results 1 to 6 of 6

Thread: loops in QML ?

  1. #1
    Join Date
    Nov 2016
    Posts
    4
    Platforms
    Windows

    Default loops in QML ?

    Hi i need to make alot of rectangles and i wonder if there are any loop commands in qml ?

    this kind of rectangle 169 times ;/

    Rectangle{
    width: chart.width / 13
    height: char.height / 13
    anchors.top: parent
    color: "lightgrey"
    id: item1
    border.width: 1

    Label{
    text: "text"
    anchors.centerIn: parent
    }
    }

    thx

  2. #2
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: loops in QML ?

    Absolutely. You may want to look at the Repeater QML element
    Something along these lines should work (untested):
    Qt Code:
    1. Repeater {
    2. model: 169
    3. Rectangle{
    4. width: chart.width / 13
    5. height: char.height / 13
    6. anchors.top: parent
    7. x: (1024/170) * index
    8. color: "lightgrey"
    9. id: item1
    10. border.width: 1
    11.  
    12. Label{
    13. text: "text"+index
    14. anchors.centerIn: parent
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    Of course you can use models with much greater complexity than a simple number.
    Last edited by sedi; 23rd November 2016 at 20:33.

  3. #3
    Join Date
    Nov 2016
    Posts
    4
    Platforms
    Windows

    Default Re: loops in QML ?

    Thx alot sedi!

  4. #4
    Join Date
    Nov 2016
    Posts
    4
    Platforms
    Windows

    Default Re: loops in QML ?

    well repeater can not solve my problems or i can not figure it out
    problems i have are id of all items as well as anchoring and putting text
    Qt Code:
    1. id: ab
    2. anchors.left: aa.right
    3. label text: "AB"
    4.  
    5. id: ac
    6. anchors.left: ab.right
    7. label text: "AC"
    8.  
    9. id: ad
    10. anchors.left: ac.right
    11. label text: "AD"
    To copy to clipboard, switch view to plain text mode 
    it will be matrix 13x13 and i should be able to change each element by clicking on it by a mouse - change color and label ,
    can i do it w/o id in rectangles at all ?
    i need also those rectangle have different values on start

  5. #5
    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: loops in QML ?

    Quote Originally Posted by itwasduke View Post
    it will be matrix 13x13 and i should be able to change each element by clicking on it by a mouse - change color and label ,
    can i do it w/o id in rectangles at all ?
    i need also those rectangle have different values on start
    For a grid like positioning you can just put the Repeater into a Grid element.
    When the repeater creates its delegates, it will hand them over to its parent. If the parent is a Grid, it will position them in as many columns (or rows) as you specify
    E.g. this creates a grid with 13 columns, number of rows depends on the number of items, in this case 2 rows
    Qt Code:
    1. Grid {
    2. columns: 13
    3.  
    4. Repeater {
    5. model: 26
    6. Text {
    7. text: model.index
    8. }
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Each delegate can of course have its own MouseArea for mouse handling, etc.

    Cheers,
    _

  6. #6
    Join Date
    Nov 2016
    Posts
    4
    Platforms
    Windows

    Default Re: loops in QML ?

    thx i will play with that also, need to read about that mouse area also again thx

Similar Threads

  1. GUI interaction with loops
    By Ini in forum Qt Programming
    Replies: 3
    Last Post: 10th March 2016, 13:56
  2. Message loops of different GUI toolkits
    By elizabeth.h1 in forum Qt Programming
    Replies: 4
    Last Post: 29th July 2009, 08:30
  3. Combining Event Loops
    By Gimpyfuzznut in forum Qt Programming
    Replies: 5
    Last Post: 10th July 2009, 06:08
  4. for loops in c++
    By baray98 in forum General Programming
    Replies: 16
    Last Post: 19th January 2009, 14:09
  5. QApplication and widgets' loops
    By Placido Currò in forum Qt Programming
    Replies: 7
    Last Post: 31st January 2008, 12:13

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.