seanchas116 / qtimgui

Qt (QOpenGLWidget / QOpenGLWindow) backend for ImGui
MIT License
362 stars 93 forks source link

Upgrade to > Qt5.15 -6 and ImGUI > v1.87 + fixes keyboard and mouse handling & widget samples #44

Closed moezb closed 1 year ago

suy commented 1 year ago

The PR doesn't compile yet on Qt 5 and/or Linux. I'll see if I can provide a linux implementation for the key mapping. For the compile errors on Qt 5, I needed to apply this changes:

diff --git i/src/ImGuiRenderer.cpp w/src/ImGuiRenderer.cpp
index da7c76f..306e088 100644
--- i/src/ImGuiRenderer.cpp
+++ w/src/ImGuiRenderer.cpp
@@ -5,7 +5,7 @@
 #include <QMouseEvent>
 #include <QClipboard>
 #include <QCursor>
-#include <QWidget> 
+#include <QDebug>

 #ifdef ANDROID
@@ -347,7 +347,7 @@ void ImGuiRenderer::onMouseMove(QMouseEvent* event) {
     assert(event != nullptr);
     ImGuiIO& io = ImGui::GetIO();
     if (!MouseTracked)  MouseTracked = true;
-    MousePos = ImVec2(static_cast<float>(event->position().x()), static_cast<float>(event->position().y()));
+    MousePos = ImVec2(static_cast<float>(event->pos().x()), static_cast<float>(event->pos().y()));
     io.AddMousePosEvent(MousePos.x, MousePos.y);
 }

diff --git i/src/ImGuiRenderer.h w/src/ImGuiRenderer.h
index 6c29f84..4ea6d42 100644
--- i/src/ImGuiRenderer.h
+++ w/src/ImGuiRenderer.h
@@ -1,5 +1,6 @@
 #pragma once

+#include <QWindow> // WId
 #include <QOpenGLExtraFunctions>
 #include <QObject>
 #include <QPoint>
diff --git i/src/QtImGui.cpp w/src/QtImGui.cpp
index 5da2c1b..ebb812a 100644
--- i/src/QtImGui.cpp
+++ w/src/QtImGui.cpp
@@ -83,7 +83,7 @@ public:
     }

     QPointF mapToGlobal(const QPointF& pos) const override {
-        return w->mapToGlobal(pos);
+        return w->mapToGlobal(pos.toPoint());
     }

     WId nativeHandle() const override {
@@ -166,7 +166,7 @@ public:
     }

     QPointF mapToGlobal(const QPointF& pos) const override {
-        return w->mapToGlobal(pos);
+        return w->mapToGlobal(pos.toPoint());
     }

     WId nativeHandle() const override {
seanchas116 commented 1 year ago

Looks like it doesn't compile on some platforms so I merged it to the separate upgrade-imgui branch.