Results 1 to 9 of 9

Thread: Using an If condition in a QML delegate?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    47
    Thanks
    10

    Default Using an If condition in a QML delegate?

    Hi,

    I'm having an issue where I need to draw a different colored Rectangle based on a condition. OR better yet is it possible to use 2 different delegates?

    So for instance
    if for instance I get a value from the model such as "active" then the rectangle I should create should be green.

    If I get "not active" the rectangle will look different.

    THe problem is I don't know how I can use an if condition in the delegate. Currently I have:


    Qt Code:
    1. ListView {
    2. id: calendarListView
    3. x: 7
    4. y: 96
    5. width: 587
    6. height: 418
    7.  
    8. model: callsonholdModel
    9.  
    10. delegate:
    11.  
    12. Rectangle {
    13. id: calendarCellHolder
    14. height: 124
    15. border.width: 2
    16. border.color: "#CFCFCF"
    17. width: calendarHeader.width
    18.  
    19. //HERE IS WHERE I NEED TO DECIDE WHAT RECTANGLE TO DRAW. CURRENTLY ITS JUST DRAWING ALL THE SAME RECTANGLE.
    20.  
    21. Rectangle {
    22. id: activeMeetingRect
    23.  
    24. width: calendarHeader.width - 30
    25. height: 84
    26. radius: 9
    27.  
    28. anchors.top:calendarCellHolder.top
    29. anchors.right: calendarCellHolder.right
    30. anchors.left: calendarCellHolder.left
    31.  
    32. anchors.topMargin: 20
    33. anchors.bottomMargin: 20
    34. anchors.leftMargin: 15
    35. anchors.rightMargin: 15
    36.  
    37. gradient: Gradient {
    38. GradientStop {
    39. position: 0
    40. color: "#5ffb26"
    41. }
    42.  
    43. GradientStop {
    44. position: 1
    45. color: "#000000"
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 



    EDIT: I actually just found out I could wrap the Rectangle's with a component { id: Delegate1 Rect{...} } component { id: Delegate2 Rect{...} }

    so really I just need to see if I can use an if/else inside the delegate to switch between Delegate1 and Delgate2.


    Thanks
    Last edited by technoViking; 9th November 2010 at 02:31.

Similar Threads

  1. Replies: 2
    Last Post: 30th June 2010, 10:48
  2. Is delegate necessary here?
    By scythe in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2010, 19:59
  3. Replies: 4
    Last Post: 5th March 2010, 18:03
  4. Sleep condition in QT
    By santhoshv84 in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2008, 12:07
  5. Delegate but when
    By uygar in forum Qt Programming
    Replies: 1
    Last Post: 12th October 2007, 20:28

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.