Results 1 to 2 of 2

Thread: Different actions on ListElements

  1. #1
    Join Date
    Nov 2015
    Posts
    3
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows Android

    Question Different actions on ListElements

    Hi. I want to make a working MouseArea on ListElements. If I just add MouseArea to an Item, then every ListElement would do the same thing. How do i make a working menu of these two (I mean making them do different things on click). Let's say Name1 should change it's name onclick, and Name2 should close app.
    Qt Code:
    1. ListView {
    2. id: listView2
    3. x: 20
    4. y: 430
    5. orientation: ListView.Horizontal
    6. anchors.rightMargin: 20
    7. anchors.leftMargin: 20
    8. anchors.bottomMargin: 10
    9. anchors.top: listView1.bottom
    10. anchors.right: parent.right
    11. anchors.bottom: parent.bottom
    12. anchors.left: parent.left
    13. anchors.topMargin: 50
    14. model: ListModel {
    15.  
    16. ListElement {
    17. name: "Name1"
    18. sourcepath: "icon1.png"
    19. }
    20. ListElement {
    21. name: "Name2"
    22. sourcepath: "icon2.png"
    23. }
    24. }
    25. delegate: Item {
    26. x: 5
    27. width: 150
    28. height: 40
    29. Row {
    30. id: row2
    31. spacing: 0
    32. Image {
    33. width: 40
    34. height: 40
    35. source: sourcepath
    36. }
    37. Text {
    38. text: name
    39. font.bold: true
    40. anchors.verticalCenter: parent.verticalCenter
    41. }
    42. }
    43. }
    44. }
    To copy to clipboard, switch view to plain text mode 
    Also how do I add smth like a button, that would add listelement with choosen values.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Different actions on ListElements

    If you put a MouseArea into your delegate, then each item will have its own mouse area.

    You can either use a model value or the model's index to decide what you want to do in each of them.

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Icamer (5th May 2016)

Similar Threads

  1. Actions in QDcokWidget
    By rouge in forum Newbie
    Replies: 3
    Last Post: 3rd November 2011, 10:40
  2. help with QSignalMapper and actions
    By andreime in forum Newbie
    Replies: 1
    Last Post: 9th August 2009, 19:24
  3. Menubar actions
    By srohit24 in forum Qt Programming
    Replies: 9
    Last Post: 23rd July 2009, 12:35
  4. Get the actions from a toolbar
    By jano_alex_es in forum Newbie
    Replies: 3
    Last Post: 20th May 2009, 10:02
  5. Actions and what to do with them?
    By krsmichael in forum Qt Tools
    Replies: 2
    Last Post: 20th January 2006, 23:08

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.