Results 1 to 6 of 6

Thread: QML, ListView and Frustration

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2012
    Posts
    5
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default QML, ListView and Frustration

    I have a C++ QWidget project in which I'd like to use QML for a couple of lists I have in the application. However, I find that doing something as simple as highlighting an item that is clicked on is proving to be difficult. I can't wait to see what a frustration this is will be when I go to add a scroll bar to my list. Anyway, I'm sure it's just because I'm new to QML but still, it's infuriating.

    I have a QML file with some sample model data that looks like:

    Qt Code:
    1. import QtQuick 1.0
    2.  
    3. Item
    4. {
    5. width: 300
    6. height: 200
    7.  
    8. ListModel
    9. {
    10. id: myModel2
    11.  
    12. ListElement { text: "List Item 1" }
    13. ListElement { text: "List Item 2" }
    14. ListElement { text: "List Item 3" }
    15. ListElement { text: "List Item 4" }
    16. ListElement { text: "List Item 5" }
    17. ListElement { text: "List Item 6" }
    18. }
    19.  
    20. Component
    21. {
    22. id: beerDelegate
    23.  
    24. Rectangle
    25. {
    26. id: beerDelegateRectangle
    27. height: beerDelegateText.height * 1.5
    28. width: parent.width
    29.  
    30. Text
    31. {
    32. id: beerDelegateText
    33. text: "<b>" + modelData + "</b> <i>(" + modelData + ")</i>"
    34. }
    35.  
    36. MouseArea
    37. {
    38. anchors.fill: parent
    39. onClicked:
    40. {
    41. console.log("clicked: " + modelData + " at index: " + index);
    42. beerList.currentIndex = index;
    43. }
    44. }
    45. }
    46. }
    47.  
    48. ListView
    49. {
    50. id: beerList
    51. anchors.fill: parent
    52. model: myModel2
    53. delegate: beerDelegate
    54.  
    55. highlightFollowsCurrentItem: true
    56. highlight: Rectangle
    57. {
    58. width: parent.width
    59. color: "red"
    60. }
    61.  
    62. focus: true
    63. }
    64. }
    To copy to clipboard, switch view to plain text mode 

    This is adapted from a couple examples I found online. All I'm trying to do with now is get an item to be highlighted in red when I click on it. I thought that by defining the "highlight" property in my ListView (beerlist) and handling "onClicked" it should do it but.. ugh...

    This is incredibly frustration and makes little sense to me right now. Help, please?
    Last edited by zethon; 8th December 2012 at 15:09.

Similar Threads

  1. listview problem (i need help)
    By rimie23 in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2012, 19:03
  2. should i use listview ?
    By rimie23 in forum Qt Programming
    Replies: 20
    Last Post: 9th May 2012, 22:40
  3. qml listview
    By Le_B in forum Qt Quick
    Replies: 1
    Last Post: 25th May 2011, 13:01
  4. osx dylib frustration
    By gri in forum General Programming
    Replies: 3
    Last Post: 16th May 2009, 15:55
  5. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 12:05

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.