That could have been a solution, but the rendering of the child widget is not in our hands, so it will take time to make that work. Meanwhile, I have another solution in mind, to draw the child widget separately as another window. But there are problems with that:
I have two windows say A and B, A being the iPad image widget (QFrame) and B being the child widget rendered through OpenGL. I need B to always stay on top of A. The ideal way would have been to make B a child widget within A, and it was working fine, but due to the above reasons, and we have to move out B out of A and make it a standalone window. So now we have to ensure that B is a separate window and always appears on top of A. This we can do through raise() call on B and always call it when we detect a click on A to ensure that even though A has been clicked, B is still on top of it.
Problem is, Mac has a feature called Mission Control, where you can now see both windows separately, and there if you click A, the app will show up maximized with A on top of B (and since A is bigger than B size wise, it covers up B completely and there is no way to go back without launching Mission Control again and choosing B! And we cannot detect a click on A there, plus more importantly, we don't want to show B as a separate widget). So I though about making B a tool widget, so that only A shows up in Mission Control, and clicking it does not alter the behavior of a tool widget B, which continues to remain on top.
I first tried this:
b->setGeometry(400,40,40,100);
b->setStyleSheet("background: green;");
b->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
b->show();
QFrame* b = new QFrame();
b->setGeometry(400,40,40,100);
b->setStyleSheet("background: green;");
b->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
b->show();
To copy to clipboard, switch view to plain text mode
This works, B does not show up as a separate window in Mission Control and stays on top of A. Until you open a normal Finder window and see B disappearing. From this link, it looks like a known feature, and the suggested workaround is to set the Qt::WA_MacAlwaysShowToolWindow flag to true, which I tried next:
b->setGeometry(400,40,40,100);
b->setStyleSheet("background: green;");
b->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
b->setAttribute(Qt::WA_MacAlwaysShowToolWindow,true);
b->show();
QFrame* b = new QFrame();
b->setGeometry(400,40,40,100);
b->setStyleSheet("background: green;");
b->setWindowFlags(Qt::FramelessWindowHint | Qt::Tool);
b->setAttribute(Qt::WA_MacAlwaysShowToolWindow,true);
b->show();
To copy to clipboard, switch view to plain text mode
Same effect, the tool widget always hides when the app loses focus. So I decided to try TooTip, and came up with this:
b->setGeometry(400,40,40,100);
b->setStyleSheet("background: green;");
b->setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip);
b->show();
QFrame* b = new QFrame();
b->setGeometry(400,40,40,100);
b->setStyleSheet("background: green;");
b->setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip);
b->show();
To copy to clipboard, switch view to plain text mode
Now this works, does not hide the tool widget when app loses focus. But the problem is, it never hides at all! Even if you click other applications and they come into view, the widget B appears on top of them as well! I added this line to see if it works, it didn't. Same result:
b->setAttribute(Qt::WA_MacAlwaysShowToolWindow,false);
b->setAttribute(Qt::WA_MacAlwaysShowToolWindow,false);
To copy to clipboard, switch view to plain text mode
So I next tried
b->setWindowFlags(Qt::FramelessWindowHint | Qt:: WindowStaysOnTopHint);
b->setWindowFlags(Qt::FramelessWindowHint | Qt:: WindowStaysOnTopHint);
To copy to clipboard, switch view to plain text mode
This also behaves in the same way as ToolTip, B always stays on top of all other applications, there doesn't seem to be a way to hide it.
If I can do this, this will be a good replacement solution in place of drawing B inside A, thus we can draw A smoothly and put B on top of it without it being affected.
Bookmarks