How to get a unique WindowRef in a dockable Qt application on Mac

Posted by Robin on Stack Overflow See other posts from Stack Overflow or by Robin
Published on 2009-07-20T11:13:56Z Indexed on 2010/05/08 22:08 UTC
Read the original article Hit count: 239

Filed under:
|

How do I get a unique WindowRef from a Qt application that includes docked windows on the Mac?

My code boils down to:

int main(int argc, char* argv[])
{
   QApplication* qtApp = new QApplication(argc, argv);
   MyQMainWindow mainwin;
   mainwin.show();
}

class MyQMainWindow : public QMainWindow
{
   //...
   QDockWidget* mDock;
   MyQWidget* mDrawArea;
   QStackedWidget* mCentralStack;
};

MyQMainWindow::MyQMainWindow()
{
   mDock = new QDockWidget(tr("Docked Widget"), this);
   mDock->setMaximumWidth(180);
   //...
   addDockWidget(Qt::RightDockWidgetArea, mDock);

   mDrawArea = new MyQWidget(this);
   mCentralStack = new QStackedWidget();
   mCentralStack->addWidget(mDrawArea);
   // Other widgets added to stack in production code.

   setCentralWidget(mCentralStack);

   //...
}

(Apologies if the above isn't syntactically correct, it's just easier to illustrate than to describe.)

I added the following temporary code at the end of the above constructor:

HIViewRef view1 = (HIViewRef) mDrawArea->winId();
HIViewRef view2 = (HIViewRef) mDock->winId();

WindowRef win1 = HIViewGetWindow(view1);
WindowRef win2 = HIViewGetWindow(view2);

My problem is that view1 and view2 are different, but win1 and win2 are the same!

I tried the following equivalent on Windows:

HWND win1 = (HWND)(mCentralDrawArea->winId());
HWND win2 = (HWND)(mDock1->winId());

This time win1 and win2 are different.

I need the window handle to pass on to a 3rd party SDK so that it can draw into the central area only.

BTW, I appreciate that the winId() method comes with lots of portability warnings, but a substantial refactor is out of the question for me. The same goes for using Carbon instead of Cocoa.

Thanks.

© Stack Overflow or respective owner

Related posts about qt

Related posts about mac