Here's an example of what I'm trying to achieve, using the GreedyMouseHook sample code as a base (the relevant part is inside handleMouseEvent):
#include <UT/UT_DSOVersion.h> #include <DM/DM_EventTable.h> #include <DM/DM_MouseHook.h> #include <DM/DM_VPortAgent.h> #include <UI/UI_Event.h> #include <QtCore/qcoreapplication.h> #include <QtWidgets/qmainwindow.h> class DM_GreedyMouseEventHook : public DM_MouseEventHook { public: DM_GreedyMouseEventHook(DM_VPortAgent &vport) : DM_MouseEventHook(vport, DM_VIEWPORT_ALL_3D) { } ~DM_GreedyMouseEventHook() override { } bool handleMouseEvent(const DM_MouseHookData &hook_data, UI_Event *event) override { if ((event->state.values[W] & UI_RIGHT_BUTTON) && (event->state.altFlags & UI_SHIFT_KEY)) { if (event->reason == UI_VALUE_START) { // This will not work, the widget is not coupled with Houdini's main thread widget = std::make_unique<QWidget>(); widget.get()->resize(640, 480); widget.get()->setWindowTitle("Hello, world!!!"); widget.get()->show(); } } return true; } bool handleMouseWheelEvent(const DM_MouseHookData &hook_data, UI_Event *event) override { return false; } bool handleDoubleClickEvent(const DM_MouseHookData &hook_data, UI_Event *event) override { return false; } bool allowRMBMenu(const DM_MouseHookData &hook_data, UI_Event *event) override { return false; } private: std::unique_ptr<QWidget> widget; // I'm using unique_prt so I don't need to deal with memory management, // but I'm open to other suggestions. }; // DM_GreedyMouseHook is a factory for DM_GreedyMouseEventHook objects. class DM_GreedyMouseHook : public DM_MouseHook { public: DM_GreedyMouseHook() : DM_MouseHook("Greedy", 0) { } DM_MouseEventHook *newEventHook(DM_VPortAgent &vport) override { return new DM_GreedyMouseEventHook(vport); } void retireEventHook(DM_VPortAgent &vport, DM_MouseEventHook *hook) override { // Shared hooks might deference a ref count, but this example just // creates one hook per viewport. delete hook; } }; void DMnewEventHook(DM_EventTable *table) { table->registerMouseHook(new DM_GreedyMouseHook); }
The problems so far are:
- The widget is not tied to Houdini's main thread, which I believe is necessary for the UI to show up.
- There's no QApplication involved which usually acts as an entry point for the application.
Is it possible to do what I want to achieve, to build custom UI using Qt and HDK?
Thanks in advance!