Results 1 to 2 of 2

Thread: Problem of Focus QMacNativeWidget

  1. #1

    Default Problem of Focus QMacNativeWidget

    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.

  2. #2

    Default Re: Problem of Focus QMacNativeWidget

    Hello,

    I've found a solution:
    Add
    Qt Code:
    1. QApplication::setAttribute(Qt::AA_MacPluginApplication);
    To copy to clipboard, switch view to plain text mode 
    before
    Qt Code:
    1. QApplication app(argc, argv);
    To copy to clipboard, switch view to plain text mode 
    It seems to work.

Similar Threads

  1. Focus problem
    By waynew in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2010, 01:24
  2. QLineEdit focus problem
    By matteo.cozzaglio in forum Qt Programming
    Replies: 3
    Last Post: 14th July 2009, 14:13
  3. QX11EmbedContainer problem with focus
    By PhoenixRevived in forum Qt Programming
    Replies: 0
    Last Post: 14th November 2007, 05:34
  4. QGraphicsTextItem focus problem
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 26th June 2007, 17:25
  5. Tab/Enter focus problem
    By b1 in forum Qt Programming
    Replies: 4
    Last Post: 23rd October 2006, 23:34

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.