-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Qt and Dear ImGui Direct3D Custom Widget Child/Parent Issue #2281
Comments
I also wanted to mention, that this only happens when I use the HWND of the widget. But if I move all that code from the widget to be in the MainWindow(basically getting the HWND of the main window), it would work perfectly fine and I could fully interact with the ImGui widgets. But this is a problem, as if I give the direct3d device the handle of the MainWindow, it will draw everything on top of all Qt widgets, which is why I created the QDirect3DWidget so all the scene is encapsulated in one place and I can also use the Qt widgets at the same time.
Even if I remove that line in the ImGui examples the hover events will work and the widgets will be showed highlighted, but of course won't be able to drag and interact as this is just for debugging purposes. |
Oh wow...I've spent some time on this and that's it! static void ImGui_ImplWin32_UpdateMousePos()
{
ImGuiIO& io = ImGui::GetIO();
// Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
if (io.WantSetMousePos)
{
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
::ClientToScreen(g_hWnd, &pos);
::SetCursorPos(pos.x, pos.y);
}
// Set mouse position
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
POINT pos;
HWND hActive = ::GetActiveWindow();
if ((hActive == g_hWnd || ::IsChild(hActive , g_hWnd)) && ::GetCursorPos(&pos))
if (::ScreenToClient(g_hWnd, &pos))
io.MousePos = ImVec2((float)pos.x, (float)pos.y);
} @ocornut You made my day! Thanks a lot for the references! I also wonder at the same time why isn't it merged into the release? |
Because I haven’t had time to look into it, and the function call that it is trying to replace was originally intentionally added to solve a problem with multi-viewports.
|
Oh well...I'm extremely happy now that I can use and get on with ImGui in my projects thanks to you! and also looking forward to see the upcoming future of it. So big thanks for everything again! :) |
Applied this change to master now. |
Hey again @ocornut, if (::GetForegroundWindow() == g_hWnd) I think what you really want to check in this case is something similar to this: static bool g_isWindowActive = false;
BOOL CALLBACK EnumChildProc(_In_ HWND hWnd, _In_ LPARAM lParam)
{
if (g_hWnd == hWnd)
{
g_isWindowActive = true;
return FALSE;
}
g_isWindowActive = false;
return TRUE; // Return true will continue the enumeration of all child handles.
}
static bool IsGivenWindowActive()
{
HWND const hParent = ::GetActiveWindow();
if (hParent == g_hWnd)
{
g_isWindowActive = true;
return true;
}
EnumChildWindows(hParent, EnumChildProc, NULL);
return g_isWindowActive;
} Then we can use it in our problematic check like so: if (IsGivenWindowActive() && ::GetCursorPos(&pos)) And I don't think there is a big concern of performance here and normally you wouldn't have many handles(HWND) for a render window. But in a situation where you have a parent window and we give it a child window handle to render to (for example in my case where I render in Qt), then this should do a proper job. Let me know what you think :) EDIT: |
I pushed a change using ::IsChild() now. Let me know if it works for you! |
Perfect! Thank you once again! |
Hi everyone :)
I've been trying to integrate ImGui into one of my projects using Qt and I'm having troubles to use it in a qt widget.
Basically I have a MainWindow in Qt which promotes the custom widget that the implementation can be found here:
https://github.com/giladreich/QtDirect3D/tree/master/src/QDirect3D9ImGuiWidget
And I promote that custom widget as the centeral widget.
In terms of rendering everything works great, but for some reason passing the messages to the ImGui proc doesn't work correctly. The ImGui widgets remains unresponsive while the rendering window is fully responsive.
I've looked into the part in ImGui code where ImGui::UpdateManualResize:
https://github.com/ocornut/imgui/blob/master/imgui.cpp#L4671
And this code never gets executed even though I do pass the event chain into the ImGui as you can see in the project sample that I added into GitHub:
https://github.com/giladreich/QtDirect3D/blob/master/src/QDirect3D9ImGuiWidget/QDirect3D9Widget.cpp#L221
I've spent some time on this trying to understand why it happens and I got a feeling that it has something to do with the way Qt handles the win32 api event chain and passing forward the messages that somehow conflicts with the ImGui ones.
There is also a ticket in Qt about KEYS messages that I already found a workaround for it:
https://bugreports.qt.io/browse/QTBUG-42183
Can anyone help me with this please? I would really appreciate this!
I hope I supplied all the necessary information to debug this, but if not, please do not hesitate to ask me!
Version/Branch of Dear ImGui:
Version: 1.67
Branch: Release
https://github.com/giladreich/QtDirect3D/tree/master/src/QDirect3D9ImGuiWidget
Compiler: msvc141
Operating System: Windows 10
Qt Version: 5.12 msvc141 x32
The text was updated successfully, but these errors were encountered: