Mac的通知窗口.有或没有Qt

  • 本文关键字:Qt 窗口 通知 Mac c++ qt macos
  • 更新时间 :
  • 英文 :


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

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

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

Qt::WA_ShowWithoutActivating不影响任何东西

有办法吗?我准备在那里实现原生Carbon/Cocoa解决方案,但Qt是首选。或者我在Mac哲学上是错的,我应该用另一种方式通知用户?

Update Growl不支持编辑器行通知,是吗?

我做到了!

#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一样好的行为:

  • 它并没有抢走秀上的焦点。(网上搜索两周)
  • 那里的控件处理第一次用户点击,而其他窗口需要一个额外的点击来激活。
  • 当窗口被激活时,同一应用程序的其他窗口不会冒泡到前面。
  • 还有一个小问题,但至少有一个简单的解决方案。或者甚至可以离开。

你听说过咆哮吗?Growl是一个非常令人印象深刻的通知应用程序,你可以捆绑和使用你的应用程序。Adium——一个流行的OS X即时通讯应用——使用它来发送所有通知。

http://growl.info/

您可以实现Growl。http://growl.info/documentation/developer/

在mac上试试:

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

我刚刚测试了这些标志

Qt::FramelessWindowHint |Qt::WindowSystemMenuHint |Qt::WindowStaysOnTopHint

 setFocusPolicy(Qt::NoFocus);
 setAttribute(Qt::WA_ShowWithoutActivating,true); 

没有Cocoa或Carbon代码的窗口标志/掩码。

最新更新