Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Grab mouseMoveEvent inside a QChart which is inside a QChartView
Forum Updated to NodeBB v4.3 + New Features

Grab mouseMoveEvent inside a QChart which is inside a QChartView

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nuvoloso
    wrote on last edited by
    #1

    I have the following code using Python and PyQt:

    import sys
    from PyQt5.QtWidgets import QMainWindow, QApplication
    from PyQt5.QtChart import QChart, QChartView, QLineSeries, QValueAxis
    from PyQt5 import QtCore, QtGui
    
    class MainWindow(QMainWindow):
        class ChartView(QChartView):
            def __init__(self, chart):
                super().__init__(chart)        
    
            def mouseMoveEvent(self, event):
                print("ChartView.mouseMoveEvent", event.pos().x(), event.pos().y())
    
                return QChartView.mouseMoveEvent(self, event)
    
        class Chart(QChart):
            def __init__(self):
                super().__init__()
    
            def mouseMoveEvent(self, event):
                print("Chart.mouseMoveEvent", event.pos().x(), event.pos().y())
    
                return QChart.mouseMoveEvent(self, event)
    
        def __init__(self, args):
            super().__init__()
    
            chartView = self.ChartView(self.Chart())
            chartView.setRenderHint(QtGui.QPainter.Antialiasing)
            chartView.setRubberBand(QChartView.HorizontalRubberBand)
    
            chartView.chart().createDefaultAxes()
            chartView.chart().legend().hide()
            chartView.chart().addAxis(QValueAxis(), QtCore.Qt.AlignBottom)
            chartView.chart().addAxis(QValueAxis(), QtCore.Qt.AlignLeft)
    
            ls = QLineSeries()
            ls.append(0, 0)
            ls.append(9, 9)
            ls.attachAxis(chartView.chart().axisX())
            ls.attachAxis(chartView.chart().axisY())
            chartView.chart().addSeries(ls)
    
            self.setCentralWidget(chartView)
            self.show()
    
    if __name__ == '__main__':
        app = QApplication(sys.argv)
    
        mainWindow = MainWindow(sys.argv)
        sys.exit(app.exec_())
    

    The problem is that in the code above mouseMoveEvent is only emitted for ChartView. But I would like to have the mouseMoveEvent emitted for Chart, rather than for ChartView. How could I accomplish this? If it's not possible to have the mouseMoveEvent triggered for Chart, how could I translate event.pos() to QChart coordinates inside ChartView.mouseMoveEvent?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved