Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Native Mac Views in QT App - Problems with focus/events
Powerpaule last edited by
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:
So, hopefully this is not a Qt Bug and I'm doing something wrong. I also tried to use this line:
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!