user140053
user140053

Reputation:

Stay on top with Qt on OSX

With Qt 4.8, I want to set my frame "stay on top". Qt way isn't perfect because it needs to recreate the windows that involves an ugly flickering.

Under Win32, it exists a native method :

SetWindowPos(winId(), <HWND_TOPMOST:HWND_NOTOPMOST>, 0,0,0,0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);

But What code do I have to use under OS-X ?

Upvotes: 1

Views: 1583

Answers (1)

Cameron Tinker
Cameron Tinker

Reputation: 9789

Here's the code I use to set a window topmost across Linux, Mac and Windows:

setWindowFlags(
    #ifdef Q_OS_MAC
        Qt::SubWindow | 
    #else
        Qt::Tool |
    #endif
        Qt::FramelessWindowHint |
        Qt::WindowSystemMenuHint |
        Qt::WindowStaysOnTopHint
    );

You can see a demonstration of the code working by cloning this repository: https://github.com/pcmantinker/Tray-Notification-System

I built this repository to make a notification system similar to Mac OS X's Growl. It also has been optimized so that it doesn't steal focus when running a full screen application which is great if you're playing a game or watching a video. It should give you a start.

Upvotes: 8

Related Questions