Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Native Mac Views in QT App - Problems with focus/events
Forum Updated to NodeBB v4.3 + New Features

Native Mac Views in QT App - Problems with focus/events

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Powerpaule
    wrote on last edited by
    #1

    Hi,

    i'm using Cocoa's NSTextView and NSScrollView in a QT 5.0.2 Application. As there isn't QMacCocoaViewContainer supported any more in qt5, i have to add the NSViews myself, by the following way:

    @
    NSView* parentView = reinterpret_cast<NSView*>(parent->winId()); // parent is the parent QWidget
    [parentView addSubview:(NSView*)scrollView]; // scrollview is NSScrollView containing NSTextView
    @

    In general it works, but there are some problems with the focus.
    The first thing is, that if an other Qt-Widget like QTextWidget or QListWidget has focus, it wont lose the focus when I click on the NSTextView.
    But the bigger problem is, using NSView elements has some strange effects on some Qt Widgets. For example if I have a QListWidget, i can't do anything with it as soon as it has the focus. Then I can not scroll it, it is impossible to select items or to drag them. The only solution is to focus an other Qt Widget, for example QTextWidget, that works fine even if I use NSViews, and then I can reclick on the QListWidget and select one item. After this it is focused and impossible to do anything with it again.

    I found out that the problem occurs at the moment I call the parent widget's function winId(). So if there is only this line in the code and the others above are commented out so that the NSScrollView is not added to the parent and not visible, the problem occurs too:

    @
    parent->winId();
    @

    So, hopefully this is not a Qt Bug and I'm doing something wrong. I also tried to use this line:
    @
    setAttribute(Qt::WA_NativeWindow);
    @
    but it doesn't change anything.

    So anyone wo has an idea what the problem/solution could be?
    Using Qt < 5.0 would not be a great option...
    Thanks a lot!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved