<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body text="#000000" bgcolor="#ffffff">
    Hi, <br>
    <br>
    I have a strange effect with hover events and QGraphicsItem.<br>
    <br>
    The example below demonstrate the problem, the hover events are
    emitted <br>
    only on the border of the item but not on the item himsef.<br>
    <br>
    If I don't draw a border, events are never emitted.<br>
    <br>
    Platform    Linux-2.6.32-33-generic-i686-with-Ubuntu-10.04-lucid<br>
    Qt              4.6.2  (probably, the problem is here)<br>
    Python       2.6.5<br>
    PyQt          4.7.2<br>
    Sip             4.10.1<br>
    <br>
    Regards<br>
    <br>
    <br>
    # -*- coding: utf-8 -*-<br>
    <br>
    from PyQt4 import QtCore, QtGui<br>
    <br>
    class Ui_MainWindow(object):<br>
        def setupUi(self, MainWindow):<br>
            MainWindow.resize(400, 400)<br>
            self.centralwidget = QtGui.QWidget(MainWindow)<br>
            self.gridLayout = QtGui.QGridLayout(self.centralwidget)<br>
            self.verticalLayout = QtGui.QVBoxLayout()<br>
            self.viewer = QtGui.QGraphicsView(self.centralwidget)<br>
            self.verticalLayout.addWidget(self.viewer)<br>
            self.scene = QtGui.QGraphicsScene()<br>
            self.scene.setSceneRect(0, 0, 300, 300)<br>
            self.viewer.setScene(self.scene)<br>
            self.item = PixmapItem(self.viewer, None, self.scene)<br>
            self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)<br>
            MainWindow.setCentralWidget(self.centralwidget)<br>
            MainWindow.show()<br>
    <br>
    class PixmapItem(QtGui.QGraphicsPixmapItem):<br>
        def __init__(self, viewer, parent=None, scene=None):<br>
            super(PixmapItem, self).__init__(parent, scene)<br>
            self.viewer = viewer<br>
            self.setFlags(QtGui.QGraphicsItem.ItemIsMovable |<br>
                    QtGui.QGraphicsItem.ItemSendsScenePositionChanges)<br>
            self.setAcceptHoverEvents(True)<br>
            self.old_cursor = self.viewer.cursor()<br>
    <br>
            color = QtGui.QColor()<br>
            color.setRgb(150, 220, 250, 40)<br>
            border = QtGui.QColor()<br>
            border.setRgb(30, 40, 220, 255)<br>
            painter = QtGui.QPainter()<br>
            pix = QtGui.QPixmap(QtCore.QSize(200, 200))<br>
            pix.fill(color)<br>
            painter.begin(pix)<br>
            painter.setPen(QtGui.QPen(border, 2,<br>
                                  QtCore.Qt.SolidLine,
    QtCore.Qt.RoundCap,<br>
                                  QtCore.Qt.MiterJoin))<br>
            painter.drawRect(0.0, 0.0, 200.0, 200.0)<br>
            painter.end()<br>
            self.setPixmap(pix)<br>
            self.setPos(50, 50)<br>
            self.show()<br>
    <br>
        def hoverEnterEvent(self, event):<br>
            print "Enter event in pixmap item"<br>
            self.setCursor(QtCore.Qt.CrossCursor)<br>
            event.accept()<br>
    <br>
        def hoverLeaveEvent(self, event):<br>
            print "Leave event from pixmap item"<br>
            self.viewer.setCursor(self.old_cursor)<br>
            event.accept()<br>
    <br>
        def hoverMoveEvent(self, event):<br>
            print "hover move event on pixmap item"<br>
            event.accept()<br>
    <br>
    if __name__ == "__main__":<br>
        import sys<br>
        app = QtGui.QApplication(sys.argv)<br>
        MainWindow = QtGui.QMainWindow()<br>
        ui = Ui_MainWindow()<br>
        ui.setupUi(MainWindow)<br>
        <br>
        sys.exit(app.exec_())<br>
    <div class="moz-signature">-- <br>
      Vincent V.V.<br>
      <a href="https://launchpad.net/oqapy">Oqapy</a> . <a
        href="https://launchpad.net/qarte+7">Qarte+7</a> . <a
        href="https://launchpad.net/paqager">PaQager</a></div>
  </body>
</html>