PDA

View Full Version : Overloading QGraphicsView function from Qt Designer



drumboy354
15th November 2011, 17:25
Hello!

I'm having a bit of trouble with overloading a function for a QGraphicsView of mine. The QGraphicsView was created in Qt Designer and is called nodeDropWindow. In this example I'm trying to overload the wheelEvent but I just want to get anything working. This is in my mainForm() class where setupUI is called. From my understanding all I would have to implement is:


@pyqtSignature("QEvent")
def on_nodeDropWindow_wheelEvent(self, event):
print("Hi!")

So what I"m trying to do is just get my console to print "Hi!" whenever I use my mouse wheel over the graphics window. This seems so simple to me but I can't get it working :-( Anybody have any ideas? Thanks!

drumboy354
16th November 2011, 22:19
No one has any ideas on how to hook up functions to a widget in Qt Designer? :-(

drumboy354
17th November 2011, 01:04
Sorry another response: I explained the problem in a lot more detail and posted some code if anyone cares :-)

http://www.qtforum.org/article/36967/overload-qgraphicsview-function-from-qt-designer.html#post115806

norobro
17th November 2011, 02:18
QGraphicsView::wheelEvent() is not a signal so there is nothing to connect. What you want to do is override wheelEvent() not overload it.

I've just dabbled in Python so I'm not sure this is correct, but at the bottom of your mainWindow class add the following and delete the "self.connect" statement:
// added this line so next line would indent
self.nodeDropGraphicsView.wheelEvent = self.wheelEvent

def wheelEvent(self, event):
print("wheel event")

drumboy354
17th November 2011, 04:28
Ohh man that was it! Dang okay I was definitely confusing the wheelEvent with a signal. Dang that's confusing. I think I was thinking that when the mouse wheel is scrolled it emits a signal (or something) and that's where I was getting confused. That makes a lot more sense, thanks a lot norobro!