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. #1
    Join Date
    Jun 2012
    Posts
    58
    Qt products
    Qt4
    Thanks
    13

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

    {quick 2.0, Qml Qt 5.1 beta}

    I wanted to know if such an idiom would be possible in Qml: Below I have objLeftColumn which expects its children to expose a boolean m_bIsSelected and a MouseArea alias m_mouseProperty and uses them to make the collection of such children mutually exclusive, ie., only one of them can be in selected state. The followin works fine but I need to repeat it every time I want and specially if I wanted it for Row etc.
    Qt Code:
    1. Column {
    2. id: objLeftColumn
    3.  
    4. property int m_iLastButtonClicked: -1
    5. property int m_iCurrentButtonClicked: -1
    6.  
    7. onM_iCurrentButtonClickedChanged: {
    8. if(m_iLastButtonClicked != -1) {
    9. objLeftColumn.children[m_iLastButtonClicked].m_bIsSelected = false
    10. }
    11. m_iLastButtonClicked = m_iCurrentButtonClicked
    12. }
    13.  
    14. Repeater {
    15. id: objLeftColumnRepeater
    16.  
    17. model: 5
    18.  
    19. delegate: ABCD {
    20. id: objABCD
    21.  
    22. m_mouseProperty.onClicked: {
    23. if(m_bIsSelected) {
    24. objLeftColumn.m_iCurrentButtonClicked = index
    25. }
    26. else {
    27. objLeftColumn.m_iLastButtonClicked = -1
    28. objLeftColumn.m_iCurrentButtonClicked = -1
    29. }
    30. }
    31. }
    32. }
    33. }
    To copy to clipboard, switch view to plain text mode 

    Can I write a generic objLeftColumn (in a separate qml file) that could arrange the given Items in Column while aslo dealing with exclusivity of their selection?

    The idea is instead of giving the component to the delegate right there an then, I'll give it later and for each instantiation of the component (depending on numeric value of model above and below) the delegate: in Repeater should behave similarly.

    eg., in psedo code:

    in Exclusive.qml:
    Qt Code:
    1. Column {
    2. id: objLeftColumn
    3.  
    4. property int m_iLastButtonClicked: -1
    5. property int m_iCurrentButtonClicked: -1
    6.  
    7. property alias m_delegate: objLeftColumnRepeater.delegate
    8.  
    9. onM_iCurrentButtonClickedChanged: {
    10. if(m_iLastButtonClicked != -1) {
    11. objLeftColumn.children[m_iLastButtonClicked].m_bIsSelected = false
    12. }
    13. m_iLastButtonClicked = m_iCurrentButtonClicked
    14. }
    15.  
    16. Repeater {
    17. id: objLeftColumnRepeater
    18.  
    19. model: 5
    20. onItemAdded: {
    21. //state of item can be manipulated but want to
    22. //add behaviour to the item (like accessing a function through virtual mechanism in c++) eg:
    23. /*item {
    24.   m_mouseProperty.onClicked: {
    25.   //do something
    26.   }
    27.   }*/
    28. }
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 

    in SomeOther.qml:
    Qt Code:
    1. Exclusive {
    2. m_delegate: ABCD
    3. }
    4.  
    5. Exclusive {
    6. m_delegate: DEFG
    7. }
    To copy to clipboard, switch view to plain text mode 

    etc..So this way Column in Exclusive is more generic and can be called with any Item assigned to its (Repeater's) delegate: and will behave similarly. Requirements: the item should expose m_mouseProperty (alias for MouseArea) and m_bIsSelected (bool) property.
    Last edited by ustulation; 18th June 2013 at 06:59.

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.