Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Is it possible to override functions of widgets drawn in QT designer?
Q74r3wq- last edited by Q74r3wq-
Found out that I can actually override
QMainWindow. I must have missed it when examing the document.
I'm trying to call a function when the mouse clicks a QGraphicsView/QGraphicsScene (AFAIK they are bounded brothers).
First try is to call a
on_MyView_clicked()which didn't work. After a bit of search I found that
QGraphicsViewdoesn't allow this kind of thing (but I can do it with a button). I researched further and found a lot of posts here and on Stackoverflow saying that one should subclass
However I don't know how to do that as I drawed the widget in QT designer so it is not generated by code.
Question: Is there a way to do it without dynamically generating a
QGraphicsViewwith a subclassed
QGraphicsScene? I think I can also subclass
QMainWindowand override from there, but I do prefer not to subclass anything at the moment.
well to override events handlers for a class, there is no way around subclassing.
One can use an event filter to catch events but generally
subclassing is the most flexible way.
- However I don't know how to do that as I drawed the widget in QT designer so it is not generated by code.
It's possible to use QCreators promote feature.
That allows you to make the subclass and then promote a normal the widget (in Designer) to your new type.
So you dont have to stop using your UI file and can also easy use subclassed widgets.
its not complicated to use. you just give it the class name of your new subclassed widget and the where to find it. (the .h files it lives in)