Event filter for getting mouse position */
| 64 | Event filter for getting mouse position |
| 65 | */ |
| 66 | bool MainWindow::eventFilter(QObject *target, QEvent *event) |
| 67 | { |
| 68 | if (target == m_chart) { |
| 69 | if (event->type() == QEvent::MouseMove) { |
| 70 | // When the mouse is over a data-point then fetch that data-point |
| 71 | // that belongs to the mouse-position and print the data value. |
| 72 | auto *mouseEvent = static_cast<QMouseEvent *>(event); |
| 73 | QPointF pos = mouseEvent->pos(); |
| 74 | QModelIndex index = m_lines->indexAt(pos.toPoint()); |
| 75 | if (index.isValid()) { |
| 76 | qDebug() << "Mouse position" << pos << "Data:" << m_model.data(index).toDouble(); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | return QWidget::eventFilter(target, event); |
| 81 | } |
| 82 | |
| 83 | void MainWindow::on_lineTypeCB_currentIndexChanged(int index) |
| 84 | { |