Results 1 to 1 of 1

Thread: listview issue

  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default listview issue

    Hi,

    I am trying to create a custom combobox using listview, can you please advice my problem.

    Below is my listview code:

    Qt Code:
    1. ListView {
    2. id: comboList
    3.  
    4. property var currentValue
    5.  
    6. anchors.fill: parent
    7.  
    8. boundsBehavior: Flickable.StopAtBounds
    9. interactive: false
    10. clip: true
    11.  
    12. focus: true
    13.  
    14. onCurrentIndexChanged: {
    15. if (comboList.model.get(comboList.currentIndex).value !== undefined)
    16. {
    17. comboList.currentValue = comboList.model.get(comboList.currentIndex).value
    18. comboBox.valueChanged();
    19. }
    20. }
    21.  
    22. delegate: Rectangle {
    23. readonly property bool isCurrent: ListView.isCurrentItem
    24. readonly property bool hovered: mouseArea.containsMouse
    25.  
    26. width: parent.width
    27. height: itemLayout.implicitHeight + 10
    28. color: hovered ? "light blue" : "transparent"
    29.  
    30. RowLayout {
    31. id: itemLayout
    32.  
    33. anchors {
    34. margins: 3
    35. right: parent.right
    36. left: parent.left
    37. verticalCenter: parent.verticalCenter
    38. }
    39.  
    40. Text {
    41. id: itemText
    42. Layout.fillWidth: true
    43.  
    44. color: hovered ? "white" : "black"
    45. horizontalAlignment: Qt.AlignLeft
    46. verticalAlignment: Qt.AlignVCenter
    47.  
    48. text: model.item
    49. }
    50. }
    51.  
    52. MouseArea {
    53. id: mouseArea
    54. anchors.fill: parent
    55. hoverEnabled: true
    56.  
    57. onClicked: {
    58. comboList.currentIndex = index;
    59. }
    60. }
    61. }
    62. highlightFollowsCurrentItem: false
    63. highlight: Rectangle {
    64. y: comboList.currentItem.y
    65.  
    66. Behavior on y { NumberAnimation { duration: 100 } }
    67.  
    68. width: comboList.currentItem.width
    69. height: comboList.currentItem.height
    70.  
    71. color: "light blue"
    72. }
    73. }
    To copy to clipboard, switch view to plain text mode 

    All I wanted is to remove the highlight on the currentItem once the mouse hovers into another item. Is there a way to turn off the highlight once the mouse enters into the list view?

    I wanted to copy the behavior of the basic ComboBox element, please advise. TIA.
    Last edited by joko; 13th July 2015 at 19:25.

Similar Threads

  1. listview
    By ganeshgladish in forum Newbie
    Replies: 1
    Last Post: 23rd June 2013, 11:51
  2. Qml Listview
    By ganeshgladish in forum Newbie
    Replies: 1
    Last Post: 19th June 2013, 09:41
  3. should i use listview ?
    By rimie23 in forum Qt Programming
    Replies: 20
    Last Post: 9th May 2012, 23:40
  4. qml listview
    By Le_B in forum Qt Quick
    Replies: 1
    Last Post: 25th May 2011, 14:01
  5. listview
    By addu in forum Qt Programming
    Replies: 2
    Last Post: 11th May 2009, 13: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.