Hello everybody,

I am facing a problem with the use of QMacNativeWidget. Based on the example of code from the documentation of theQMacNativeWidget, I have simply tried to put a QTextEdit on a mac window. However, I cannot get the focus on the QTextEdit.

Qt Code:
  1. #include <QtGui/QtGui>
  2. #include <QtGui/qmacnativewidget_mac.h>
  3. #import <Cocoa/Cocoa.h>
  4.  
  5. int main(int argc, char **argv)
  6. {
  7. QApplication app(argc, argv);
  8.  
  9. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  10. NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(200, app.desktop()->height() - 200, 239, 200)
  11. styleMask:NSTitledWindowMask | NSClosableWindowMask
  12. | NSMiniaturizableWindowMask | NSResizableWindowMask
  13. backing:NSBackingStoreBuffered defer:NO];
  14.  
  15. QMacNativeWidget *nativeWidget = new QMacNativeWidget();
  16. nativeWidget->move(0, 0);
  17. nativeWidget->setPalette(QPalette(Qt::red));
  18. nativeWidget->setAutoFillBackground(true);
  19. QVBoxLayout *layout = new QVBoxLayout();
  20. QTextEdit *txtEdit = new QTextEdit("An Embedded Qt Button!", nativeWidget);
  21. txtEdit->setAttribute(Qt::WA_LayoutUsesWidgetRect); // Don't use the layout rect calculated from QMacStyle.
  22. layout->addWidget(txtEdit);
  23. nativeWidget->setLayout(layout);
  24.  
  25. // Adjust Cocoa layouts
  26. NSView *nativeWidgetView = reinterpret_cast<NSView *>(nativeWidget->winId());
  27. NSView *contentView = [window contentView];
  28. [contentView setAutoresizesSubviews:YES];
  29. [nativeWidgetView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
  30. [nativeWidgetView setAutoresizesSubviews:YES];
  31. NSView *txtEditView = reinterpret_cast<NSView *>(txtEdit->winId());
  32. [txtEditView setAutoresizingMask:NSViewWidthSizable];
  33.  
  34. // Add the nativeWidget to the window.
  35. [contentView addSubview:nativeWidgetView positioned:NSWindowAbove relativeTo:nil];
  36. nativeWidget->show();
  37. txtEdit->show();
  38.  
  39. // Show the window.
  40. [window makeKeyAndOrderFront:window];
  41. [pool release];
  42.  
  43. return app.exec(); // gives us the same behavior in both
  44. }
To copy to clipboard, switch view to plain text mode 

This is the result, I cannot edit nor select the text (it stays gray).



Anyone has an idea why this happen?. I cannot find more documentation and example about QMacNativeWidget.
Thanks in advance for any help.