<meta http-equiv="content-type" content="text/html; charset=utf-8"><div>Yea thats definately not the reason because everything in my original code looks fine,what could be the problem exactly?<br><br>Sent from my iPhone</div><div><br>On 08 May 2016, at 1:14 AM, Elvis Stansvik [via Python] <<a href="/user/SendEmail.jtp?type=node&node=5190312&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>> wrote:<br><br></div><blockquote style='border-left:2px solid #CCCCCC;padding:0 1em' type="cite"><div>
2016-05-07 23:05 GMT+02:00 sw33tz <<a href="/user/SendEmail.jtp?type=node&node=5190298&i=0" target="_top" rel="nofollow" link="external">[hidden email]</a>>:
<br>> Thanks for replying...I've updated my code but I still cant get it to work:
<br>>
<br>> class graphics_Object(QtGui.QGraphicsPixmapItem):
<br>> def __init__(self, parent=None):
<br>> super(switch_Object, self).__init__(parent)
<br><br>Should be graphics_Object here, not switch_Object ^ (in the call to super).
<br><br>Don't think that is the problem though, but it's late here and I have to sleep.
<br><br>Elvis
<br><div class="shrinkable-quote"><div class='shrinkable-quote'><br>> pixmap = QtGui.QPixmap("item.png")
<br>> self.graphics_pixItem = QtGui.QGraphicsPixmapItem(pixmap.scaled(40,
<br>> 40, QtCore.Qt.KeepAspectRatio))
<br>>
<br>> self.graphics_pixItem.setFlag(QtGui.QGraphicsPixmapItem.ItemIsSelectable)
<br>>
<br>> self.graphics_pixItem.setFlag(QtGui.QGraphicsPixmapItem.ItemIsMovable)
<br>> self.graphics_pixItem.setAcceptHoverEvents(True)
<br>>
<br>>
<br>> def hoverEnterEvent(self, event):
<br>> print 'hello'
<br>>
<br>> class graphicsScene(QtGui.QGraphicsScene):
<br>> def __init__(self, parent=None):
<br>> super(graphicsScene, self).__init__(parent)
<br>>
<br>> def mousePressEvent(self, event):
<br>> self.graphics_item = graphics_Object()
<br>> def mouseReleaseEvent(self, event)
<br>> self.addItem(self.self.graphics_item.graphics_pixItem)
<br>> self.graphics_item.self.graphics_pixItem.setPos(event.scenePos())
<br>>
<br>> class Form(QtGui.QMainWindow):
<br>> def __init__(self):
<br>> super(Form, self).__init__()
<br>> self.ui = uic.loadUi('form.ui')
<br>>
<br>> self.scene = graphicsScene()
<br>> self.ui.view.setScene(self.scene)
<br>>
<br>> self.setMouseTracking(True)
<br>>
<br>>
<br>> On Sat, May 7, 2016 at 10:55 PM, Elvis Stansvik [via Python] <[hidden
<br>> email]> wrote:
<br>>>
<br>>> Hi Nesibe,
<br>>>
<br>>> 2016-05-07 19:46 GMT+02:00 sw33tz <[hidden email]>:
<br>>> > I want some small text to pop up when I have my curser over a
<br>>> > QGraphicsItem
<br>>> > in my QGraphicsScene. I have a class that inherits from QGraphicsItem,
<br>>> > and
<br>>> > this represents my graphical items in the scene.
<br>>> >
<br>>> > I tried using the QGraphicsItem.hoverEnterEvent and I also set the
<br>>> > setAcceptHoverEvents(True), but I still can't enable that hover event. I
<br>>> > also came across an event filter method but I'm not sure where to
<br>>> > implement
<br>>> > it.
<br>>>
<br>>> This seems to work here:
<br>>>
<br>>>
<br>>> test.py:
<br>>>
<br>>> from sys import argv, exit
<br>>>
<br>>> from PyQt5.QtCore import Qt
<br>>> from PyQt5.QtWidgets import QApplication
<br>>> from PyQt5.QtWidgets import QGraphicsEllipseItem
<br>>> from PyQt5.QtWidgets import QGraphicsScene
<br>>> from PyQt5.QtWidgets import QGraphicsView
<br>>> from PyQt5.QtWidgets import QMainWindow
<br>>>
<br>>>
<br>>> class MyItem(QGraphicsEllipseItem):
<br>>>
<br>>> def __init__(self, parent=None):
<br>>> super(MyItem, self).__init__(parent)
<br>>>
<br>>> self.setRect(50, 50, 50, 50)
<br>>> self.setBrush(Qt.red)
<br>>> self.setAcceptHoverEvents(True)
<br>>>
<br>>> def hoverEnterEvent(self, event):
<br>>> print('hover enter')
<br>>>
<br>>> def hoverLeaveEvent(self, event):
<br>>> print('hover leave')
<br>>>
<br>>>
<br>>> app = None
<br>>>
<br>>>
<br>>> def main():
<br>>> global app
<br>>>
<br>>> app = QApplication(argv)
<br>>>
<br>>> scene = QGraphicsScene()
<br>>> scene.addItem(MyItem())
<br>>>
<br>>> view = QGraphicsView()
<br>>> view.setScene(scene)
<br>>>
<br>>> window = QMainWindow()
<br>>> window.setCentralWidget(view)
<br>>> window.show()
<br>>>
<br>>> exit(app.exec_())
<br>>>
<br>>>
<br>>> if __name__ == '__main__':
<br>>> main()
<br>>>
<br>>>
<br>>> Hope that helps.
<br>>>
<br>>> Best regards,
<br>>> Elvis
<br>>>
<br>>> >
<br>>> > Should I install the event filter in the QGraphicsItem class, or the
<br>>> > scene?
<br>>> > I tried both and I'm still not getting the desired result. I want to be
<br>>> > able
<br>>> > to hover over all the items in the scene.
<br>>> >
<br>>> >
<br>>> > class HoverEventFilter(QtCore.QObject):
<br>>> > def eventFilter(self, receiver, event):
<br>>> > if (event.type() == QtCore.QEvent.HoverEnter):
<br>>> > # this is for test purposes
<br>>> > print 'hover event'
<br>>> > return True
<br>>> > else:
<br>>> > # Call Base Class Method to Continue Normal Event Processing
<br>>> > return super(HoverEventFilter, self).eventFilter(receiver,
<br>>> > event)
<br>>> >
<br>>> >
<br>>> >
<br>>> > --
<br>>> > View this message in context:
<br>>> > <a href="http://python.6.x6.nabble.com/Hover-Event-for-a-QGraphicsItem-tp5190283.html" target="_top" rel="nofollow" link="external">http://python.6.x6.nabble.com/Hover-Event-for-a-QGraphicsItem-tp5190283.html</a><br>>> > Sent from the PyQt mailing list archive at <a href="http://nabble.com" target="_top" rel="nofollow" link="external">Nabble.com</a>.
<br>>> > _______________________________________________
<br>>> > PyQt mailing list [hidden email]
<br>>> > <a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_top" rel="nofollow" link="external">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>>> _______________________________________________
<br>>> PyQt mailing list [hidden email]
<br>>> <a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_top" rel="nofollow" link="external">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>>>
<br>>> ________________________________
<br>>> If you reply to this email, your message will be added to the discussion
<br>>> below:
<br>>>
<br>>> <a href="http://python.6.x6.nabble.com/Hover-Event-for-a-QGraphicsItem-tp5190283p5190286.html" target="_top" rel="nofollow" link="external">http://python.6.x6.nabble.com/Hover-Event-for-a-QGraphicsItem-tp5190283p5190286.html</a><br>>> To unsubscribe from Hover Event for a QGraphicsItem, click here.
<br>>> NAML
<br>>
<br>>
<br>>
<br>> ________________________________
<br>> View this message in context: Re: Hover Event for a QGraphicsItem
<br>>
<br>> Sent from the PyQt mailing list archive at <a href="http://nabble.com" target="_top" rel="nofollow" link="external">Nabble.com</a>.
<br>>
<br>> _______________________________________________
<br>> PyQt mailing list <a href="/user/SendEmail.jtp?type=node&node=5190298&i=1" target="_top" rel="nofollow" link="external">[hidden email]</a>
<br>> <a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_top" rel="nofollow" link="external">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></div>_______________________________________________
</div>PyQt mailing list <a href="/user/SendEmail.jtp?type=node&node=5190298&i=2" target="_top" rel="nofollow" link="external">[hidden email]</a>
<br><a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" target="_top" rel="nofollow" link="external">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a>
<br>
<br>
<hr noshade="noshade" size="1" color="#cccccc">
<div style="color:#444; font: 12px tahoma,geneva,helvetica,arial,sans-serif;">
<div style="font-weight:bold">If you reply to this email, your message will be added to the discussion below:</div>
<a href="http://python.6.x6.nabble.com/Hover-Event-for-a-QGraphicsItem-tp5190283p5190298.html" target="_top" rel="nofollow" link="external">http://python.6.x6.nabble.com/Hover-Event-for-a-QGraphicsItem-tp5190283p5190298.html</a>
</div>
<div style="color:#666; font: 11px tahoma,geneva,helvetica,arial,sans-serif;margin-top:.4em;line-height:1.5em">
To unsubscribe from Hover Event for a QGraphicsItem, <a href="" target="_top" rel="nofollow" link="external">click here</a>.<br>
<a href="http://python.6.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" rel="nofollow" style="font:9px serif" target="_top" link="external">NAML</a>
</div></div></blockquote>
<br/><hr align="left" width="300" />
View this message in context: <a href="http://python.6.x6.nabble.com/Hover-Event-for-a-QGraphicsItem-tp5190283p5190312.html">Re: Hover Event for a QGraphicsItem</a><br/>
Sent from the <a href="http://python.6.x6.nabble.com/PyQt-f1792048.html">PyQt mailing list archive</a> at Nabble.com.<br/>