PDA

View Full Version : Problem of Focus QMacNativeWidget



skuallpa
20th July 2010, 08:54
Hello everybody,

I am facing a problem with the use of QMacNativeWidget. Based on the example of code from the documentation of theQMacNativeWidget (http://doc.trolltech.com/4.6/qmacnativewidget.html), I have simply tried to put a QTextEdit on a mac window. However, I cannot get the focus on the QTextEdit.


#include <QtGui/QtGui>
#include <QtGui/qmacnativewidget_mac.h>
#import <Cocoa/Cocoa.h>

int main(int argc, char **argv)
{
QApplication app(argc, argv);

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSWindow *window = [[NSWindow alloc] initWithContentRect:NSMakeRect(200, app.desktop()->height() - 200, 239, 200)
styleMask:NSTitledWindowMask | NSClosableWindowMask
| NSMiniaturizableWindowMask | NSResizableWindowMask
backing:NSBackingStoreBuffered defer:NO];

QMacNativeWidget *nativeWidget = new QMacNativeWidget();
nativeWidget->move(0, 0);
nativeWidget->setPalette(QPalette(Qt::red));
nativeWidget->setAutoFillBackground(true);
QVBoxLayout *layout = new QVBoxLayout();
QTextEdit *txtEdit = new QTextEdit("An Embedded Qt Button!", nativeWidget);
txtEdit->setAttribute(Qt::WA_LayoutUsesWidgetRect); // Don't use the layout rect calculated from QMacStyle.
layout->addWidget(txtEdit);
nativeWidget->setLayout(layout);

// Adjust Cocoa layouts
NSView *nativeWidgetView = reinterpret_cast<NSView *>(nativeWidget->winId());
NSView *contentView = [window contentView];
[contentView setAutoresizesSubviews:YES];
[nativeWidgetView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
[nativeWidgetView setAutoresizesSubviews:YES];
NSView *txtEditView = reinterpret_cast<NSView *>(txtEdit->winId());
[txtEditView setAutoresizingMask:NSViewWidthSizable];

// Add the nativeWidget to the window.
[contentView addSubview:nativeWidgetView positioned:NSWindowAbove relativeTo:nil];
nativeWidget->show();
txtEdit->show();

// Show the window.
[window makeKeyAndOrderFront:window];
[pool release];

return app.exec(); // gives us the same behavior in both
}

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

http://img828.imageshack.us/img828/6051/embededqtextedit.png

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

skuallpa
21st July 2010, 14:19
Hello,

I've found a solution:
Add
QApplication::setAttribute(Qt::AA_MacPluginApplica tion); before
QApplication app(argc, argv);
It seems to work.