Results 1 to 9 of 9

Thread: mousearea containsmouse property

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

    Default mousearea containsmouse property

    Hi,

    I have some quick questions to clarify:

    1) Is there a workaround already for MouseArea containsMouse property when the area moves under the mouse? Based on the docs the property is still outdated.
    2) Can parent clip property be overridden by the child? Is there a possible workaround? I tried using Z index but it's not working. I want the child rectangle to overlap from parent where clip property set to true.

    Thanks.
    Last edited by joko; 3rd December 2014 at 18:18.

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

    Default Re: mousearea containsmouse property

    Quote Originally Posted by joko View Post
    1) Is there a workaround already for MouseArea containsMouse property when the area moves under the mouse? Based on the docs the property is still outdated.
    What do you mean the property is "outdated"? MouseArea reacts on mouse movement, it has no way of knowing it has moved under the cursor.

    2) Can parent clip property be overridden by the child?
    No.
    Is there a possible workaround?
    Make the "child" a "sibling" rather than a child. Or do some smart clipping using shaders.

    I want the child rectangle to overlap from parent where clip property set to true.
    Why do you enable clipping then?
    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
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: mousearea containsmouse property

    Quote Originally Posted by wysota View Post
    What do you mean the property is "outdated"? MouseArea reacts on mouse movement, it has no way of knowing it has moved under the cursor.
    I mean the property is not updated, because when I pressed the mouse and then move it, containsmouse is still true. Am i understanding it correctly?

    http://qt-project.org/doc/qt-5/qml-q...ainsMouse-prop

    Why do you enable clipping then?
    I enabled the parent so that it won't display when scrolled because the other siblings have transparent background.
    The rectangle that I wanted to overlap into other parent's siblings is my custom dropdown.

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

    Default Re: mousearea containsmouse property

    Quote Originally Posted by joko View Post
    I mean the property is not updated, because when I pressed the mouse and then move it, containsmouse is still true. Am i understanding it correctly?
    As I said, the item has no way of knowing what you would like it to know.

    I enabled the parent so that it won't display when scrolled because the other siblings have transparent background.
    The rectangle that I wanted to overlap into other parent's siblings is my custom dropdown.
    Please provide some code demonstrating the problem.
    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
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: mousearea containsmouse property

    Quote Originally Posted by wysota View Post
    As I said, the item has no way of knowing what you would like it to know.
    I wanted to bind a highlighted image once it is clicked and hovered then replace it with normal image once mouse position moves.
    I used containsMouse however, like i said, the image remained highlighted after I pressed and moves the mouse.

    Please provide some code demonstrating the problem.
    parent page
    Qt Code:
    1. Rectangle
    2. {
    3.  
    4. Rectangle
    5. {
    6. id: header
    7. height: 70
    8. Layout.fillWidth: true
    9. color: "#00000000"
    10.  
    11. Text
    12. {
    13. id: title
    14. text: qsTr("Title")
    15. color: "#FFFFFF"
    16. }
    17. }
    18.  
    19. Flickable
    20. {
    21. id: main
    22. contentHeight: 200
    23. anchors.fill: parent
    24.  
    25. MouseArea
    26. {
    27. id: mouseArea
    28. anchors.fill: parent
    29. onClicked: {
    30. closePopup()
    31. }
    32. }
    33.  
    34. Rectangle
    35. {
    36. id: body
    37. anchors {
    38. top: header.bottom
    39. left: parent.left
    40. right: parent.right
    41. }
    42.  
    43. RowLayout
    44. {
    45. spacing: 30
    46. anchors.fill: parent
    47. Rectangle
    48. {
    49. width: 50
    50. Text
    51. {
    52. id: colorLbl
    53. text: qsTr("Color")
    54. anchors.verticalCenter: parent.verticalCenter
    55. }
    56. }
    57.  
    58. ListModel{
    59. id: colors
    60. ListElement{
    61. item: "Blue"
    62. }
    63. ListElement{
    64. item: "Green"
    65. }
    66. ListElement{
    67. item: "Red"
    68. }
    69. }
    70.  
    71. CustomComboBox
    72. {
    73. id: colorCmb
    74. Layout.fillWidth: true
    75. implicitHeight: 30
    76. model: colors
    77. }
    78. }
    79. }
    80. }
    81.  
    82. Rectangle
    83. {
    84. id: footer
    85. Layout.fillWidth: true
    86. color: "#00000000"
    87. anchors {
    88. left: parent.left
    89. right: parent.right
    90. bottom: parent.bottom
    91. }
    92.  
    93. Button
    94. {
    95. id: backBtn
    96. text: qsTr("Back")
    97. }
    98. }
    99.  
    100. function closePopup() {
    101. if(colorCmb.comboState === "visible") {
    102. colorCmb.comboState = ""
    103. }
    104. }
    105. }
    To copy to clipboard, switch view to plain text mode 

    CustomComboBox.qml
    Qt Code:
    1. import QtQuick 2.0
    2. import QtQuick.Layouts 1.1
    3. import QtGraphicalEffects 1.0
    4.  
    5. Item
    6. {
    7. id: container
    8.  
    9. property color color: "white"
    10. property color hoverColor: "#5692c4"
    11. property int fontSize: 12
    12. property alias model: listView.model
    13. property alias comboState: dropDown.state
    14. property int index: 0
    15.  
    16. property Component rowDelegate: defaultRowDelegate
    17.  
    18. signal valueChanged(int id)
    19.  
    20. Component
    21. {
    22. id: defaultRowDelegate
    23. Text
    24. {
    25. anchors {
    26. fill: parent
    27. rightMargin: 25
    28. }
    29. verticalAlignment: Text.AlignVCenter
    30. horizontalAlignment: Text.AlignRight
    31. font {
    32. pointSize: container.fontSize
    33. family: fontFamily
    34. }
    35. text: parent.modelItem.item
    36. }
    37. }
    38.  
    39. Rectangle
    40. {
    41. id: main
    42. anchors.fill: parent
    43. color: container.color
    44. clip: true
    45.  
    46. Image
    47. {
    48. id: arrowIcon
    49. anchors{
    50. right: main.right
    51. verticalCenter: parent.verticalCenter
    52. }
    53. fillMode: Image.PreserveAspectFit
    54. source: "/image/arrow_down.png"
    55. }
    56. }
    57.  
    58. Loader
    59. {
    60. id: topRow
    61. anchors.fill: parent
    62. focus: true
    63. clip: true
    64.  
    65. sourceComponent: rowDelegate
    66. property variant modelItem
    67. }
    68.  
    69. MouseArea
    70. {
    71. id: mouseArea
    72. anchors.fill: container
    73. onClicked: { toggle() }
    74. }
    75.  
    76. Rectangle
    77. {
    78. id: dropDown
    79. width: container.width; height: 0
    80. anchors.top: container.bottom
    81. anchors.topMargin: -1
    82.  
    83. clip: true
    84.  
    85. Behavior on height { NumberAnimation { duration: 100 } }
    86.  
    87. Component
    88. {
    89. id: myDelegate
    90.  
    91. Rectangle
    92. {
    93. width: dropDown.width; height: container.height
    94. color: "transparent"
    95.  
    96. Loader
    97. {
    98. id: loader
    99. anchors.fill: parent
    100. sourceComponent: rowDelegate
    101.  
    102. property variant modelItem: model
    103. }
    104.  
    105. property variant modelItem: model
    106.  
    107. MouseArea
    108. {
    109. id: delegateMouseArea
    110. anchors.fill: parent
    111. onEntered: listView.currentIndex = index
    112. onClicked: close(true)
    113. }
    114. }
    115. }
    116.  
    117. ListView
    118. {
    119. id: listView
    120. width: container.width; height: container.height * count
    121. delegate: myDelegate
    122. highlight: Rectangle {
    123. anchors.horizontalCenter: parent ? parent.horizontalCenter : undefined;
    124. color: container.hoverColor
    125. }
    126. boundsBehavior: Flickable.StopAtBounds
    127. }
    128.  
    129. Rectangle
    130. {
    131. id: listViewCon
    132. anchors.fill: listView
    133. color: "transparent"
    134. border.color: "lightgray"
    135. border.width: 1
    136. }
    137.  
    138. states: [
    139. State {
    140. name: "visible";
    141. PropertyChanges { target: dropDown; height: container.height * listView.count }
    142. }
    143. ]
    144. }
    145.  
    146. function toggle() {
    147. if (dropDown.state === "visible") { close(false) } else { open() }
    148. }
    149.  
    150. function open() {
    151. dropDown.state = "visible"
    152. listView.currentIndex = container.index
    153. }
    154.  
    155. function close(update) {
    156. dropDown.state = ""
    157.  
    158. if (update) {
    159. container.index = listView.currentIndex
    160. topRow.modelItem = listView.currentItem.modelItem
    161. valueChanged(listView.currentIndex)
    162. }
    163. }
    164.  
    165. Component.onCompleted: {
    166. listView.currentIndex = container.index
    167. if (listView.currentItem)
    168. topRow.modelItem = listView.currentItem.modelItem
    169. }
    170. }
    To copy to clipboard, switch view to plain text mode 

    I want the dropdown rectangle from CustomComboBox to overlap into footer rectangle.
    Last edited by joko; 4th December 2014 at 15:12.

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

    Default Re: mousearea containsmouse property

    And where do you use containsMouse?
    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
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: mousearea containsmouse property

    Quote Originally Posted by wysota View Post
    And where do you use containsMouse?
    the containsMouse is not related to the comboBox.

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

    Default Re: mousearea containsmouse property

    If you want help then please provide code that allows one to reproduce your problem. Posting meaningless code does not help.
    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.


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

    Default Re: mousearea containsmouse property

    Quote Originally Posted by wysota View Post
    If you want help then please provide code that allows one to reproduce your problem. Posting meaningless code does not help.
    Apologies. I just updated the codes.

Similar Threads

  1. Replies: 1
    Last Post: 24th November 2014, 08:28
  2. Qt Quick button mousearea issue
    By joko in forum Qt Quick
    Replies: 2
    Last Post: 21st November 2014, 09:47
  3. MouseArea
    By Viper666 in forum Qt Quick
    Replies: 6
    Last Post: 10th January 2013, 13:30
  4. Replies: 1
    Last Post: 24th October 2011, 14:49
  5. Problem with MouseArea element
    By chiru in forum Qt Quick
    Replies: 1
    Last Post: 27th November 2010, 00:23

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.