Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I need some advice from a Qt expert.

The background: I have a 3D engine (ogre3d) working in concert with Qt. The 3D Content is displayed in a widget (using a custom OS window in the client area). I'm able to overlay arbitrary Qt widgets onto the 3d world using the widget render() method and a shared bitmap. This makes a great "heads up display". I can use the standard Qt style sheets and animation using this technique.

My goal I'd like to go a step further and allow the user to move these rendered widgets using the mouse. I'd like some advice on the best way to implement this.

Possible solutions:

  • The widgets in the HUD are not part of the inheritance chain. I render them manually. They don't get events though. I could add them to the inheritance chain so they get events in the usual way. Then I would need to change them to render to my shared bitmap instead of to the operating system. I looked at this once but couldn't find enough information to implement it.
  • Capture mouse events in the 3D display widget and EMIT them to child controls. I basically create my own event handling chain.

Any suggestions on how to implement this?

I'm also considering switching to Qt5. I'm not sure how that might affect this decision.

share|improve this question

1 Answer 1

up vote 1 down vote accepted
+100

So far both solutions seem ok and none of them present any major drawback.

I guess the solution is the one you implent the quickest .

Now ...

if you choose a)

  • You need to create a render target

  • Push this as the current render target

  • draw your hud in this render target

  • pop it leaving you ogre window as the main render target

  • draw everything else here

then ..and this is the tricky part

either

  • get the pixels from the render target create a qimage and draw it

or

  • create a custom material that uses for the texture you render target's color buffer and draw a full screen quad with this material

in any case you should check tutorials 1 , 2 , 3

If you choose b)

you already figured out what to do ....

in your mouse mousePress , Released , Moved events from your qtglwindow just emit some events and whatever widgets is active or intersecting the mouse should respond to the event .

share|improve this answer
    
I implemented the hud by doing an Ogre overlay. I found a format of bitmap that the Qt QPainter and Ogre would both accept. I use that bitmap in a material in the Ogre overlay. For each frame that needs an update I clear the bitmap, call render() on each of the Qt widgets passing them the bitmap. Works very nicely. You get the style sheets and animation as well. –  Jay Dec 25 '12 at 4:34
    
If I choose option A I need to implement the Qt render target, not the ogre render target. If I choose B I need mouse clicks and whatever is needed for Qt uses to track the mouse. I'd like the hover stylesheet options to work. Any idea how hover works? I may have to break down and start going through the Qt source code. –  Jay Dec 25 '12 at 4:40
    
There is no qt Render target .. a render target is just and abstract notion in order to have the same operations if you render to a screen or to a texture(bitmap is such an old fashion way of putting it). Basically is exactly what you said you did in the first comment . Now if you choose b) check out qtgraphics scene event propagation doc.qt.digia.com/qt/… –  Mihai Sebea Dec 26 '12 at 12:28
    
Sorry, I should have said "QPaintDevice" instead of Qt Render Target. I'll have a look at that link. Thanks :) –  Jay Dec 26 '12 at 16:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.