Mac中的通知窗口.有无Qt

Pav*_*gin 5 c++ macos qt

Mac OS X上的Qt项目.我需要在顶部显示通知窗口,而不会从任何活​​动应用程序中窃取焦点.

这里的小部件构造函数部分:

setWindowFlags(
    Qt::FramelessWindowHint |
    Qt::WindowSystemMenuHint |
    Qt::Tool |
    Qt::WindowStaysOnTopHint
);
setAttribute(Qt::WA_TranslucentBackground);
Run Code Online (Sandbox Code Playgroud)

Qt :: WA_ShowWithoutActivating不会影响任何事情.

有没有办法做到这一点?我准备在那里实施原生碳/可可溶液,但Qt是首选.或许我在Mac哲学中错了,我应该以另一种方式通知用户?

更新 Growl在其通知中不支持编辑器行,是吗?

Pav*_*gin 6

我做的!

#ifdef Q_OS_MAC
#include <Carbon/Carbon.h>
#endif

NotifyWindow::NotifyWindow() : QWidget(0 /* This zero is the first point */) {

    setWindowFlags(
    #ifdef Q_OS_MAC
        Qt::SubWindow | // This type flag is the second point
    #else
        Qt::Tool |
    #endif
        Qt::FramelessWindowHint |
        Qt::WindowSystemMenuHint |
        Qt::WindowStaysOnTopHint
    );
    setAttribute(Qt::WA_TranslucentBackground);

    // And this conditional block is the third point
#ifdef Q_OS_MAC
    winId(); // This call creates the OS window ID itself.
             // qt_mac_window_for() doesn't

    int setAttr[] = {
        kHIWindowBitDoesNotHide, // Shows window even when app is hidden

        kHIWindowBitDoesNotCycle, // Not sure if required, but not bad

        kHIWindowBitNoShadow, // Keep this if you have your own design
                              // with cross-platform drawn shadows
        0 };
    int clearAttr[] = { 0 };
    HIWindowChangeAttributes(qt_mac_window_for(this), setAttr, clearAttr);
#endif
}
Run Code Online (Sandbox Code Playgroud)

我们得到几乎与Windows中相同的好行为:

  • 它并没有把重点放在秀场上.(通过互联网搜索两周)
  • 那里的控件处理第一个用户点击,而其他窗口需要额外的点击才能激活.
  • 当窗口被激活时,同一应用程序的其他窗口不会向前冒泡.
  • 和一个小问题依然,但至少它有一个简单的解决方法.甚至可以离开.