You can't have multiple inheritance from QObject, so that won't do. You could have a subclass of QPushButton where you would pass a painter pointer through a constructor. But it could be dangerous and error prone.
You can't have multiple inheritance from QObject, so that won't do. You could have a subclass of QPushButton where you would pass a painter pointer through a constructor. But it could be dangerous and error prone.
That's true, I was talking in principal, is QObject's case that would probably mean containmant (i.e QGLPushButton derives from QGLWidget and has a QPushButton).You can't have multiple inheritance from QObject
Could you explain a bit more on how you would do such a thing?You could have a subclass of QPushButton where you would pass a painter pointer through a constructor.
I mean, how would the QPainter be delivered to the QPushButton paintEvent?
Hmm... let's think about it... Maybe through some external object holding a pointer to the painter which would be updated every time the GLPainter is created. It's just a loose concept, but if there was a pointer to the painter available, one could read it through that object and use it. Of course after clipping and transforming coordinates. The problem I see is that the painter object is only created (at least I think so) when the top level widget is updated (correct me if I'm wrong), so updating a child widget would require creating such a painter first. As I said, just a loose concept and a bit unclear one, I don't have a slightest idea if this is achievable at all.
That is the point I don't get.but if there was a pointer to the painter available, one could read it through that object and use it.
Lets say I have a pointer to the openGL QPainter, in a helper object or some other place.
How can I give it to a regular QWidget subclass (not a user subclass,but like QPushButton) in order that it will use it for drawing it self...
That is the main problem I am trying to solve (if it can be solved).
Thanks for helping out with the brainstorming!![]()
You can't. That's why I said you have to subclass![]()
Hehe... ok, I thought you were suggesting to give the QPainter pointer to the Qt widgets...
I know it not possible with the Qt API (at least I could not find how), that is why I posted the question...
Hmm... I am not yet sure in which direction to go...
I mean, this will have to do with reimplementing the PaintEngine, which is created by the PaintDevice, which is the base for QWidget...
I have to read some more...
Thanks.
Reading one of the other threads in this forum I came up with an idea - maybe redirecting QPainter (QPainter::setRedirected) could help? You could redirect painting child widgets to the parent (GL based) widget's painter. It is probable that you should do some transforming/clipping of the GL painter to make it work (or maybe using the "offset" param will be enough).
That looks interesting!
I'll have a look at it - thanks.
Hi again,
I just wanted to add that I tried QPainter::setRedirected, and it works in the sence that you can use it to draw the controls in a GL context.
I do it by first redirecting the draw event of the widget I want on to a QPixmap, and then I use a GL initiated QPainter to draw this pixmap in GL context.
The problem is, that this only DRAWS the controls in GL, so these are not real object anymore under GL...
It looks like having 'responding objects' under GL will force me to do sume subclassing after all...
Bookmarks