簡體   English   中英

Mac 中的通知 window。 帶或不帶 Qt

[英]Notification window in Mac. With or without Qt

Mac OS X 上的 Qt 項目。我需要在頂部顯示通知 window 而不從任何活動的應用程序中竊取焦點。

這里是小部件構造函數部分:

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 中幾乎相同的良好行為:

  • 它並沒有偷走對表演的關注。 (在網上搜索了兩周)
  • 那里的控件處理第一次用戶點擊,而其他 windows 需要額外點擊才能激活。
  • 當 window 被激活時,同一個應用程序的另一個 windows,不要冒泡到前面。
  • 還有一個小問題,但至少它有一個簡單的解決方法。 甚至可以留下。

帕維爾,

你聽說過咆哮嗎? Growl 是一個非常令人印象深刻的通知應用程序,您可以將其捆綁並與您的應用程序一起使用。 Adium - 適用於 OS X 的流行即時消息應用程序 - 將其用於所有通知。

http://growl.info/

我剛剛測試了這些標志

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

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

沒有 Cocoa 或 window 標志/掩碼的碳代碼。 並且 notifyWindow 在 Windows 或 Linux 上工作。

在 mac 上試試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM