MCPcopy Create free account
hub / github.com/PyQt5/PyQt / mouseMoveEvent

Method mouseMoveEvent

QtChart/ToolTip.py:160–181  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

158 # self.step_y = (self.max_y - self.min_y) / (axisY.tickCount() - 1)
159
160 def mouseMoveEvent(self, event):
161 super(ChartView, self).mouseMoveEvent(event)
162 # 把鼠标位置所在点转换为对应的xy值
163 x = self._chart.mapToValue(event.pos()).x()
164 y = self._chart.mapToValue(event.pos()).y()
165 index = round((x - self.min_x) / self.step_x)
166 pos_x = self._chart.mapToPosition(
167 QPointF(index * self.step_x + self.min_x, self.min_y))
168 # print(x, pos_x, index, index * self.step_x + self.min_x)
169 # 得到在坐标系中的所有series的类型和点
170 points = [(serie, serie.at(index))
171 for serie in self._chart.series() if
172 self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y]
173 if points:
174 # 永远在轴上的黑线条
175 self.lineItem.setLine(pos_x.x(), self.point_top.y(),
176 pos_x.x(), self.point_bottom.y())
177 self.lineItem.show()
178 self.toolTipWidget.show("", points, event.pos() + QPoint(20, 20))
179 else:
180 self.toolTipWidget.hide()
181 self.lineItem.hide()
182
183 def onSeriesHoverd(self, point, state):
184 if state:

Callers

nothing calls this directly

Calls 3

yMethod · 0.80
xMethod · 0.45
showMethod · 0.45

Tested by

no test coverage detected