Results 1 to 7 of 7

Thread: High light do not upate?

  1. #1
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Question High light do not upate?

    Hi All,
    I whan to high light the current item of listview. But the highlight bar do not update when I click , it always say at top of list.
    It seems that current item never updated when mouse clicked! If I update currentItemIndex manually, the hightlight bar can move. What's wrong with it?
    Qt Code:
    1. Rectangle {
    2. width: 180; height: 200
    3. ListModel {
    4. id: contactModel
    5. ListElement {
    6. name: "Bill Smith"
    7. number: "555 3264"
    8. }
    9. ListElement {
    10. name: "John Brown"
    11. number: "555 8426"
    12. }
    13. ListElement {
    14. name: "Sam Wise"
    15. number: "555 0473"
    16. }
    17. }
    18. Component {
    19. id: contactDelegate
    20. Item {
    21. width: 180; height: 40
    22. Column {
    23. Text { text: '<b>Name:</b> ' + name }
    24. Text { text: '<b>Number:</b> ' + number }
    25. }
    26. }
    27. }
    28.  
    29. ListView {
    30. anchors.fill: parent
    31. model: contactModel
    32. delegate: contactDelegate
    33. highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
    34. focus: true
    35. }
    36. }
    To copy to clipboard, switch view to plain text mode 
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: High light do not upate?

    The current item is not updated when you click the mouse because you have no mouse areas that would accept the click and interpret it. You need to modify the currentIndex property of the view yourself if you want the current index to change upon clicking an item.
    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.


  3. #3
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: High light do not upate?

    I add mouse area to change current index. But it is ugly to hard code view id in mourse area. How can mourse area know delegate's view?
    Qt Code:
    1. ListModel {
    2. id: contactModel
    3. ListElement {
    4. name: "Bill Smith"
    5. number: "555 3264"
    6. }
    7. ListElement {
    8. name: "John Brown"
    9. number: "555 8426"
    10. }
    11. ListElement {
    12. name: "Sam Wise"
    13. number: "555 0473"
    14. }
    15. }
    16.  
    17.  
    18. Rectangle {
    19. width: 180; height: 200
    20.  
    21. Component {
    22. id: contactDelegate
    23. Item {
    24. width: 180; height: 40
    25. Column {
    26. Text { text: '<b>Name:</b> ' + name }
    27. Text { text: '<b>Number:</b> ' + number }
    28. }
    29. MouseArea{
    30. anchors.fill: parent
    31. onClicked: {
    32. testListView.currentIndex = index [COLOR="#FF0000"]# it is ugly, how can mouse area know view but not hard code view's ID?[/COLOR]
    33. }
    34. }
    35. }
    36. }
    37.  
    38. ListView {
    39. id: testListView
    40. anchors.fill: parent
    41. model: contactModel
    42. delegate: contactDelegate
    43. highlight: Rectangle { color: "lightsteelblue"; radius: 5 }
    44. focus: true
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: High light do not upate?

    Quote Originally Posted by Abel View Post
    I add mouse area to change current index. But it is ugly to hard code view id in mourse area. How can mourse area know delegate's view?
    Each item gets a "ListView" attached property which in turn has a "view" property pointing to the view itself.

    javascript Code:
    1. Component {
    2. id: contactDelegate
    3. Item {
    4. id: delegateRoot
    5. // ...
    6. MouseArea {
    7. // ...
    8. onClicked: {
    9. delegateRoot.ListView.view.currentIndex = index
    10. }
    11. }
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    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.


  5. #5
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: High light do not upate?

    wysota,
    when I try with this code,
    Qt Code:
    1. Component {
    2. id: listControlerDelegate
    3. Item{
    4. width : parent.width
    5. height: 25
    6. MouseArea{
    7. anchors.fill: parent
    8. onClicked: {
    9. // listControler.currentIndex = index
    10. [B] delegateRoot.ListView.view.currentIndex = index[/B]
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    it report that:
    ReferenceError: delegateRoot is not defined.
    How can a item know it's view?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,363
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: High light do not upate?

    Compare my code and yours. Look for "delegateRoot".
    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.


  7. #7
    Join Date
    Aug 2013
    Posts
    27
    Thanks
    3

    Default Re: High light do not upate?

    wysota,
    Thank you. After set id : delegateRoot, it works.
    I thought delegateRoot is attribute of Item, so made such mistake.

Similar Threads

  1. High DPI support on windows
    By Daylight in forum Qt Tools
    Replies: 1
    Last Post: 17th March 2014, 19:20
  2. high resolution timer
    By ChasW in forum Qt Programming
    Replies: 18
    Last Post: 24th June 2011, 18:50
  3. High CPU Utilization
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2009, 09:37
  4. qt4 with light blinking on device
    By khcbabu in forum Qt Programming
    Replies: 1
    Last Post: 9th March 2009, 15:52
  5. Light items for the graphicsView
    By maverick_pol in forum Qt Programming
    Replies: 12
    Last Post: 1st November 2007, 18:51

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.