Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. The enterEvent and leaveEvent of QGraphicsView do not match the actual show area well
Qt 6.12 LTS is out! See what's new in the release blog

The enterEvent and leaveEvent of QGraphicsView do not match the actual show area well

Scheduled Pinned Locked Moved Solved Qt for Python
4 Posts 3 Posters 1.4k 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.
  • feiyuhuahuoF Offline
    feiyuhuahuoF Offline
    feiyuhuahuo
    wrote on last edited by feiyuhuahuo
    #1

    I'm using PySide6. I created a custom QGraphicsView and I rewrite the enterEvent () function and the leaveEvent() function. But the actual working area does not match the visual area.
    ezgif.com-gif-maker.gif
    Parts of the code:

    class LossCurve(QGraphicsView):
        def __init__(self, parent=None):
            super().__init__(parent)
            self.setScene(QGraphicsScene(self))
            self.setDragMode(QGraphicsView.NoDrag)
            self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
            self.setRenderHint(QPainter.Antialiasing)
    
            self.chart = QChart()
            self.chart.setAcceptHoverEvents(True)
            self.chart.legend().hide()
            self.series = QLineSeries()
            self.chart.addSeries(self.series)
    
            self.x_axis = QValueAxis()
            self.x_axis.setLabelFormat("%i")
            self.y_axis = QValueAxis()
    
            self.chart.addAxis(self.x_axis, Qt.AlignBottom)
            self.series.attachAxis(self.x_axis)
            self.chart.addAxis(self.y_axis, Qt.AlignLeft)
            self.series.attachAxis(self.y_axis)
    
            self.scene().addItem(self.chart)
    
            self.x_legend = QGraphicsSimpleTextItem(self.chart)
            self.x_legend_text = '轮:'
            self.x_legend.setText(self.x_legend_text)
            self.y_legend = QGraphicsSimpleTextItem(self.chart)
            self.y_legend_text = '损失:'
            self.y_legend.setText(self.y_legend_text)
    
            self._callouts = []
            self._tooltip = Callout(self.chart)
    
            # self.series.clicked.connect(self.keep_callout) 
            self.series.hovered.connect(self.draw_tooltip)
            self.setMouseTracking(True)
    
        def enterEvent(self, event):
            print('enter........')
    
        def leaveEvent(self, event):
            print('leave........')
    
    eyllanescE 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you have the same issue with an empty scene ?

      Which exact version of PySide6 are you using ?
      On which platform ?
      How did you install it ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • feiyuhuahuoF feiyuhuahuo

        I'm using PySide6. I created a custom QGraphicsView and I rewrite the enterEvent () function and the leaveEvent() function. But the actual working area does not match the visual area.
        ezgif.com-gif-maker.gif
        Parts of the code:

        class LossCurve(QGraphicsView):
            def __init__(self, parent=None):
                super().__init__(parent)
                self.setScene(QGraphicsScene(self))
                self.setDragMode(QGraphicsView.NoDrag)
                self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
                self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
                self.setRenderHint(QPainter.Antialiasing)
        
                self.chart = QChart()
                self.chart.setAcceptHoverEvents(True)
                self.chart.legend().hide()
                self.series = QLineSeries()
                self.chart.addSeries(self.series)
        
                self.x_axis = QValueAxis()
                self.x_axis.setLabelFormat("%i")
                self.y_axis = QValueAxis()
        
                self.chart.addAxis(self.x_axis, Qt.AlignBottom)
                self.series.attachAxis(self.x_axis)
                self.chart.addAxis(self.y_axis, Qt.AlignLeft)
                self.series.attachAxis(self.y_axis)
        
                self.scene().addItem(self.chart)
        
                self.x_legend = QGraphicsSimpleTextItem(self.chart)
                self.x_legend_text = '轮:'
                self.x_legend.setText(self.x_legend_text)
                self.y_legend = QGraphicsSimpleTextItem(self.chart)
                self.y_legend_text = '损失:'
                self.y_legend.setText(self.y_legend_text)
        
                self._callouts = []
                self._tooltip = Callout(self.chart)
        
                # self.series.clicked.connect(self.keep_callout) 
                self.series.hovered.connect(self.draw_tooltip)
                self.setMouseTracking(True)
        
            def enterEvent(self, event):
                print('enter........')
        
            def leaveEvent(self, event):
                print('leave........')
        
        eyllanescE Offline
        eyllanescE Offline
        eyllanesc
        wrote on last edited by
        #3

        @feiyuhuahuo I do not reproduce the problem, could you provide a complete and verifiable example. In my test I had to remove the callout code. I use Linux with PySide6 6.1.2

        If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

        1 Reply Last reply
        0
        • feiyuhuahuoF Offline
          feiyuhuahuoF Offline
          feiyuhuahuo
          wrote on last edited by
          #4

          @SGaist @eyllanesc I found the reason. The two arrows are in a hoverd window and the window is frameless and has a transparent background. The real window size is showed in the below picture. So it affects the activation area of the QGraphicsView.

          屏幕截图 2021-08-26 102853.png

          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
          • Unsolved