MCPcopy Index your code
hub / github.com/PyQt5/PyQt / mouseMoveEvent

Method mouseMoveEvent

QtChart/BarStack.py:134–172  ·  view source on GitHub ↗
(self, event)

Source from the content-addressed store, hash-verified

132 QPointF(self.min_x, self.max_y))
133
134 def mouseMoveEvent(self, event):
135 super(ChartView, self).mouseMoveEvent(event)
136 pos = event.pos()
137 # 把鼠标位置所在点转换为对应的xy值
138 x = self._chart.mapToValue(pos).x()
139 y = self._chart.mapToValue(pos).y()
140 index = round(x)
141 # 得到在坐标系中的所有bar的类型和点
142 serie = self._chart.series()[0]
143 bars = [(bar, bar.at(index))
144 for bar in serie.barSets() if self.min_x <= x <= self.max_x and self.min_y <= y <= self.max_y]
145 # print(bars)
146 if bars:
147 right_top = self._chart.mapToPosition(
148 QPointF(self.max_x, self.max_y))
149 # 等分距离比例
150 step_x = round(
151 (right_top.x() - self.point_top.x()) / self.category_len)
152 posx = self._chart.mapToPosition(QPointF(x, self.min_y))
153 self.lineItem.setLine(posx.x(), self.point_top.y(),
154 posx.x(), posx.y())
155 self.lineItem.show()
156 try:
157 title = self.categories[index]
158 except:
159 title = ""
160 t_width = self.toolTipWidget.width()
161 t_height = self.toolTipWidget.height()
162 # 如果鼠标位置离右侧的距离小于tip宽度
163 x = pos.x() - t_width if self.width() - \
164 pos.x() - 20 < t_width else pos.x()
165 # 如果鼠标位置离底部的高度小于tip高度
166 y = pos.y() - t_height if self.height() - \
167 pos.y() - 20 < t_height else pos.y()
168 self.toolTipWidget.show(
169 title, bars, QPoint(x, y))
170 else:
171 self.toolTipWidget.hide()
172 self.lineItem.hide()
173
174 def handleMarkerClicked(self):
175 marker = self.sender() # 信号发送者

Callers

nothing calls this directly

Calls 5

yMethod · 0.80
xMethod · 0.45
showMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected