Mac中的通知窗口。有无Qt

时间:2011-04-28 19:06:27

标签: c++ qt macos

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

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

setWindowFlags(
    Qt::FramelessWindowHint |
    Qt::WindowSystemMenuHint |
    Qt::Tool |
    Qt::WindowStaysOnTopHint
);
setAttribute(Qt::WA_TranslucentBackground);

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

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

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

4 个答案:

答案 0 :(得分: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
}

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

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

答案 1 :(得分:4)

的Pavel,

你听说过低吼? Growl是一个非常令人印象深刻的通知应用程序,您可以捆绑和使用您的应用程序。 Adium - 一款适用于OS X的流行即时通讯应用程序 - 将其用于所有通知。

http://growl.info/

答案 2 :(得分:0)

答案 3 :(得分:0)

在Mac上尝试:

setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_AlwaysStackOnTop);