Struggling to get both the ChartView MouseArea and a QScatterSeries events working at the same time. Depending on z-order I can easily get one or the other working but not both! I've had the MouseArea as a child to the ChartView and as a sibling. Generally my approach is to have the MouseArea higher z-order than the ChartView and try to pass the signal along to the QScatterSeries but no joy. I've experimented with propagateComposedEvents = true in the MouseArea and adding an onClicked (mouse.accepted = fales). My MouseArea has onReleased and onPressed handler as well. Here's my current code:

Qt Code:
  1. Rectangle{
  2. id: chartDataRect
  3. anchors{left: parent.left; leftMargin: 30; right: metaDataRect.left; rightMargin: 10; top: headerSeparator.bottom; topMargin: 40}
  4. radius: 6
  5. height: 340
  6. color: "#ECEEEE"
  7.  
  8. ChartView {
  9. id: chartView
  10. clip: true
  11. anchors.fill: parent
  12. margins.left: 0
  13. margins.right: 0
  14. margins.top: 0
  15. margins.bottom: 0
  16. legend.visible: false
  17. backgroundColor: "transparent"
  18. antialiasing: true
  19. legend.alignment: Qt.AlignBottom
  20. theme: ChartView.ChartThemeDark
  21. width: 2.0
  22. property bool pressed: false
  23.  
  24. property var alarmTimeData: []
  25. property var alarmNameData: []
  26. property var stepData: []
  27.  
  28. property var alarmIconsList: [
  29. "qrc:/assets/Images/AlarmIcons/bell-Alarm.png",
  30. "qrc:/assets/Images/AlarmIcons/power-Alarm.png",
  31. "qrc:/assets/Images/AlarmIcons/service-Alarm.png",
  32. "qrc:/assets/Images/AlarmIcons/temperature-Alarm.png",
  33. "qrc:/assets/Images/AlarmIcons/warm-Alarm.png",
  34. ]
  35.  
  36. onSeriesRemoved: {
  37. console.log("Series Removed.")
  38. }
  39.  
  40. ValueAxis {
  41. id: timeAxis
  42. color: "#344550"
  43. min: 0
  44. max: 1
  45. labelFormat:"%.1f"
  46. labelsColor: "#FFFFFF"
  47. }
  48.  
  49. ValueAxis {
  50. id: tempAxis
  51. min: -195
  52. max: 40
  53. color: "#344550"
  54. labelFormat:"%.1f"
  55. labelsColor: "#FFFFFF"
  56. }
  57.  
  58. ScatterSeries {
  59. id: scatterSeries
  60. axisX: timeAxis
  61. axisY: tempAxis
  62. color: "red"
  63. visible: true
  64.  
  65. // TODO: Not working? Hovered does work Event propagation issue.
  66. onClicked: {
  67. toolTipAlarm.visible=true
  68. var pnt = chartView.mapToPosition(point, scatterSeries)
  69. toolTipAlarm.x = pnt.x
  70. toolTipAlarm.y = pnt.y
  71.  
  72. var stepCount=0
  73. for(var i=0 ;i<stepDataArray.length; ++i) {
  74. if(parseFloat(stepDataArray[i]).toFixed(3)===point.x.toFixed(3)) {
  75. stepCount = i
  76. break
  77. }
  78. }
  79. console.log("SDA:", stepDataArray, point.x.toFixed(3), stepCount)
  80. toolTipAlarm.text = qsTrId("Step: ") + parseInt(stepCount+1) + " | " + point.x.toFixed(3)
  81. }
  82. }
  83.  
  84. // For Displaying Images on Icon Overlay
  85. Repeater {
  86. id: rep_iconOverLay
  87.  
  88. Image {
  89. id: alarmImage
  90. source: chartView.alarmIconsList[almImage(index)]
  91. width: 15
  92. height: 15
  93. fillMode: Image.PreserveAspectFit
  94. visible: (x>0)
  95. x: showAlmIcon(index)
  96. y: checkNearby(index)
  97.  
  98. MouseArea {
  99. anchors.fill: parent
  100. propagateComposedEvents: true
  101. onClicked: {
  102. toolTipAlarm.text="Alarm: " + chartView.alarmTimeData[index] + ", " + chartView.alarmNameData[index]
  103. toolTipAlarm.visible=true
  104. toolTipAlarm.x=alarmImage.x
  105. toolTipAlarm.y=alarmImage.y
  106. }
  107. }
  108.  
  109. function almImage(idx) {
  110. if ((almSymbol[idx] === "N2") || (almSymbol[idx] === "HM")) {
  111. return EnumShared.REDBELL - 2
  112. }
  113. else if ((almSymbol[idx] === "TH") || (almSymbol[idx] === "TL")
  114. || (almSymbol[idx] === "CL") || (almSymbol[idx] === "SL")) {
  115. return EnumShared.TEMP - 2
  116. }
  117. else if ((almSymbol[idx] === "CF") || (almSymbol[idx] === "SF")) {
  118. return EnumShared.SERVICE - 2
  119. }
  120. else if (almSymbol[idx] === "PF") {
  121. return EnumShared.PWRFAIL - 2
  122. }
  123. else if (almSymbol[idx] === "SD") {
  124. return EnumShared.REDBELL - 2
  125. }
  126. else {
  127. // Error
  128. return -1
  129. }
  130. }
  131.  
  132. function showAlmIcon(idx) {
  133. if ((chartView.alarmTimeData[idx] > timeAxis.min) && (chartView.alarmTimeData[idx] < timeAxis.max)) {
  134. return chartView.mapToPosition(Qt.point(chartView.alarmTimeData[idx],0),lSeries3).x
  135. }
  136. else {
  137. return(-1)
  138. }
  139. }
  140.  
  141. function checkNearby(idx) {
  142. var newPt = chartView.mapToPosition(Qt.point(chartView.alarmTimeData[idx],0),lSeries3).x
  143. var priorPt = chartView.mapToPosition(Qt.point(chartView.alarmTimeData[idx-1],0),lSeries3).x
  144. if (newPt - priorPt < 15) {
  145. return 280
  146. }
  147. else {
  148. return 260
  149. }
  150. }
  151. }
  152. }
  153.  
  154. ToolTip{
  155. id: toolTipAlarm
  156. timeout: 1500
  157. }
  158.  
  159. Rectangle{
  160. id: zoomRect
  161. color: "#FFFFFF"
  162. opacity: 0.4
  163. visible: false
  164. }
  165. }
  166.  
  167. MouseArea {
  168. anchors.fill: chartView
  169. propagateComposedEvents: true
  170. property int lastX: 0
  171. property int lastY: 0
  172. acceptedButtons: Qt.AllButtons
  173.  
  174. onClicked: {
  175. mouse.accepted = false
  176. }
  177. onReleased: {
  178. if (mouse.button === Qt.LeftButton) {
  179. rep_iconOverLay.model=0
  180. if (lastX !== mouse.x) {
  181. chartView.scrollRight(lastX - mouse.x);
  182. lastX = mouse.x;
  183. }
  184. if (lastY !== mouse.y) {
  185. chartView.scrollDown(lastY - mouse.y);
  186. lastY = mouse.y;
  187. }
  188. rep_iconOverLay.model=chartView.alarmTimeData
  189. }
  190. else if (mouse.button === Qt.RightButton) {
  191. rep_iconOverLay.model=0
  192. chartView.zoomIn(Qt.rect(zoomRect.x, zoomRect.y, zoomRect.width, zoomRect.height));
  193. zoomRect.visible = false
  194. chartView.pressed=false
  195. rep_iconOverLay.model=chartView.alarmTimeData
  196. }
  197. }
  198. onDoubleClicked: {
  199. rep_iconOverLay.model=0
  200. chartView.zoomReset()
  201. timeAxis.min = xMinn
  202. timeAxis.max = xMaxx
  203. tempAxis.min = yMinn
  204. tempAxis.max = yMaxx
  205. rep_iconOverLay.model=chartView.alarmTimeData
  206. }
  207. onPressed: {
  208. if (mouse.button === Qt.LeftButton) {
  209. lastX = mouse.x;
  210. lastY = mouse.y;
  211. }
  212. else if (mouse.button === Qt.RightButton){
  213. chartView.pressed = false
  214. zoomRect.x = mouse.x
  215. zoomRect.y = mouse.y
  216. zoomRect.visible = true
  217. }
  218. }
  219. onMouseXChanged: {
  220. zoomRect.width = mouse.x - zoomRect.x;
  221. }
  222. onMouseYChanged: {
  223. zoomRect.height = mouse.y - zoomRect.y;
  224. }
  225. }
  226. }
To copy to clipboard, switch view to plain text mode