Results 1 to 5 of 5

Thread: z order for mouseArea doesn't work in ListView

  1. #1
    Join Date
    Sep 2015
    Posts
    12
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Default z order for mouseArea doesn't work in ListView

    Hi all,

    I have a ListView which has some items inside. What I want is when the user clicked on items, the MouseArea in items can be triggered first. (since the items appear upper layer than ListView, I think it's resonable that we expect item's MouseArea receive mouse event first.) However, my experiment shows that MouseArea in ListViews receive mouse event first. Even I tried to set z value, ListViews always has higher priority to receive mouse event.
    Does anyone who knows how I can make MouseArea in items to receive mouse event first?

    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.3
    3. import QtQuick.Window 2.2
    4.  
    5. ApplicationWindow {
    6. title: qsTr("Hello World")
    7. width: 1280
    8. height: 720
    9. visible: true
    10.  
    11. ListView{
    12. id: thisListView
    13. width: parent.width; height: parent.height
    14. delegate: thisDelegate
    15. model: thisListModel
    16. spacing: 2
    17. z:0
    18.  
    19. MouseArea{
    20. z:0
    21. anchors.fill: parent
    22. propagateComposedEvents: true
    23. onClicked: {
    24. console.log("ListView is clicked")
    25. mouse.accepted = false
    26. }
    27. }
    28. }
    29. ListModel{
    30. id: thisListModel
    31. ListElement{itemText: "1"}
    32. ListElement{itemText: "2"}
    33. ListElement{itemText: "3"}
    34. }
    35.  
    36. Component{
    37. id: thisDelegate
    38. Rectangle{
    39. width: thisListView.width; height: 30;
    40. color: "lightBlue"
    41. z: 1
    42. Text{text: itemText; anchors.centerIn: parent}
    43. MouseArea{
    44. z:1
    45. anchors.fill: parent
    46. onClicked: {
    47. console.log("Item is clicked")
    48. }
    49. }
    50. }
    51. }
    52. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: z order for mouseArea doesn't work in ListView

    You could make the mouse area a sibling of the list view

    Qt Code:
    1. Item {
    2. anchors.fill: parent
    3.  
    4. MouseArea {
    5. anchors.fill: parent
    6. }
    7.  
    8. ListView {
    9. anchors.fill: parent
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. #3
    Join Date
    Sep 2015
    Posts
    12
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Default Re: z order for mouseArea doesn't work in ListView

    Thank you, Anda_Skoa for your reply.
    I have tried that but the priority of mouse event in ListView is still higher than it's own items. Which means when I clicked the items. The console log will be
    qml: ListView is clicked
    qml: Item is clicked

    I guess that z value cannot work properly to the Item belong to Component.
    Do you know any other possible solution?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: z order for mouseArea doesn't work in ListView

    Quote Originally Posted by clarksuper0420 View Post
    I have tried that but the priority of mouse event in ListView is still higher than it's own items.
    And you are sure you have the MouseArea outside the ListView element?
    Before the ListView element in the QML code?

    Maybe post the code you have now?

    Cheers,
    _

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

    clarksuper0420 (3rd September 2015)

  6. #5
    Join Date
    Sep 2015
    Posts
    12
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows Android

    Default Re: z order for mouseArea doesn't work in ListView

    Hi Anda_Skoa,
    You just pointed out a very important mistake I made. I didn't put MouseArea before the ListView (although I did put MouseArea outside of ListView).
    Thank you very much!!! You solved my problem completely.


    Added after 58 minutes:


    Sorry, Anda_Skoa. I was too rush to say the problem is solved.
    When I tried your suggestion, it truly make item to receive the mouse event first. But when I clicked the part in ListView which doesn't contain item, there is no mouse event anymore.
    Did I do something wrong? Here is the code.
    Qt Code:
    1. import QtQuick 2.4
    2. import QtQuick.Controls 1.3
    3. import QtQuick.Window 2.2
    4.  
    5. ApplicationWindow {
    6. title: qsTr("Hello World")
    7. width: 1280
    8. height: 720
    9. visible: true
    10. Item{
    11. anchors.fill: parent
    12. MouseArea{
    13. anchors.fill: parent
    14. propagateComposedEvents: true
    15. onClicked: {
    16. console.log("ListView is clicked")
    17. mouse.accepted = false
    18. }
    19. }
    20. ListView{
    21. id: thisListView
    22. anchors.fill: parent
    23. delegate: thisDelegate
    24. model: thisListModel
    25. spacing: 2
    26. }
    27. }
    28. ListModel{
    29. id: thisListModel
    30. ListElement{itemText: "1"}
    31. ListElement{itemText: "2"}
    32. ListElement{itemText: "3"}
    33. }
    34.  
    35. Component{
    36. id: thisDelegate
    37. Rectangle{
    38. width: thisListView.width; height: 30;
    39. color: "lightBlue"
    40. Text{text: itemText; anchors.centerIn: parent}
    41. MouseArea{
    42. anchors.fill: parent
    43. onClicked: {
    44. console.log("Item is clicked")
    45. }
    46. }
    47. }
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by clarksuper0420; 3rd September 2015 at 16:40.

Similar Threads

  1. Qt Linguist *.qm doesn't work?
    By radmir in forum Newbie
    Replies: 1
    Last Post: 21st May 2014, 08:42
  2. setAxisAutoScale doesn't work
    By satoshi in forum Qwt
    Replies: 0
    Last Post: 31st December 2009, 19:49
  3. QNetworkAccessManager doesn't work
    By Floppy in forum Newbie
    Replies: 7
    Last Post: 14th November 2009, 16:32
  4. Privoxy doesn't work with qt 4.5.1
    By doep in forum Qt Programming
    Replies: 2
    Last Post: 21st June 2009, 10:55
  5. setTabStopWidth doesn't work
    By discostu in forum Qt Programming
    Replies: 3
    Last Post: 19th November 2007, 08:29

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.