Carlos Ch
Carlos Ch

Reputation: 403

Force QWidget Child to have its own Window Handle

I am trying to create a small application using Qt. What I want to do is to display in a dock widget a 3D Interface using DirectX11, other widgets in the QMainWindow will have properties to modify the behavior of what is been displayed in DX11.

The problem I am facing is that when I add a QDockWidget to QMainWindow, the dockWidgetContents function windowHandle returns NULL.

I am using an example from Get HWND on windows with Qt5 (from WId) to get the HWND. But if the function return NULL it will go up and get the HWND of the QMainWindow.

Is there any way to force a QWidget to have its own window handle?

Thanks for any advice!

Upvotes: 2

Views: 4782

Answers (1)

cloose
cloose

Reputation: 956

Yes. You have several options for that. See the topic Native Widgets vs Alien Widgets in the QWidget class documentation.

  1. Use the QT_USE_NATIVE_WINDOWS=1 in your environment.
  2. Set the Qt::AA_NativeWindows attribute on your application. All widgets will be native widgets.
  3. Set the Qt::WA_NativeWindow attribute on widgets: The widget itself and all of its ancestors will become native (unless Qt::WA_DontCreateNativeAncestors is set).
  4. Call QWidget::winId to enforce a native window (this implies 3).
  5. Set the Qt::WA_PaintOnScreen attribute to enforce a native window (this implies 3).

Upvotes: 3

Related Questions