Results 1 to 4 of 4

Thread: Can Repeater delegate in Qml be made to behave in a generic way to the given Items?

Threaded View

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

    Default Re: Can Repeater delegate in Qml be made to behave in a generic way to the given Item

    Shouldn't something like that work?

    javascript Code:
    1. Column {
    2. id: col
    3. property int selectedIndex: -1
    4.  
    5. Repeater {
    6. model: 5
    7. Rectangle {
    8. width: 200; height: 50
    9. color: col.selectedIndex == index ? "red" : "white"
    10. MouseArea {
    11. anchors.fill: parent
    12. onClicked: col.selectedIndex = index
    13. }
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 

    You can easily create a component from it like so:

    javascript Code:
    1. Column {
    2. id: col
    3. property alias delegate: rep.delegate
    4. property alias model: rep.model
    5. property int selectedIndex: -1
    6.  
    7. Repeater {
    8. id: rep
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    If you really want to, you can adjust the delegate to add a MouseArea to the delegate to have everything contained in a single component, probably more or less like so:

    javascript Code:
    1. Column {
    2. id: col
    3. property Component delegate
    4. property alias model: rep.model
    5. property int selectedIndex: -1
    6.  
    7. Repeater {
    8. id: rep
    9. }
    10. Component {
    11. id: macmp
    12. MouseArea {
    13. anchors.fill: parent
    14. onClicked: col.selectedIndex = index
    15. }
    16. }
    17. onDelegateChanged: {
    18. var obj = delegate.createInstance(rep) // or create the item elsewhere and assign it to the rep.delegate
    19. var ma = macmp.createInstance(obj)
    20. }
    21. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 18th June 2013 at 08:08.
    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. set combobox delegate on some view items
    By GrahamLabdon in forum Newbie
    Replies: 0
    Last Post: 8th March 2011, 14:36
  2. Replies: 0
    Last Post: 30th August 2010, 19:08
  3. QTreeView different item delegate for child items possible?
    By Royceybaby in forum Qt Programming
    Replies: 4
    Last Post: 7th January 2010, 21:14
  4. Replies: 0
    Last Post: 4th April 2009, 15:54
  5. Use delegate to draw different type of items
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2009, 13:16

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.