tags:

views:

301

answers:

1

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.

A: 

To wrap this up, I contacted Qt who said that this is expected behaviour and that it's unusual for a 3rd party application to require a windowref like this. They suggested looking into the widget attributes Qt::WA_PaintOnScreen and Qt::WA_NoSystemBackground on the widget.

Beyond this, I guess the fix will be to request that the 3rd party SDK is edited to take carbon / cocoa window handles.

Robin