Mac 中的通知窗口。有或没有Qt

发布于 2024-11-04 03:18:18 字数 555 浏览 0 评论 0原文

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

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

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

Qt::WA_ShowWithoutActivating 不影响任何事物。

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

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

Qt project on Mac OS X. I need to show notification window on top without stealing a focus from any active application.

Here the widget constructor part:

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

Qt::WA_ShowWithoutActivating doesn't affect anything.

Is there a way to do that? I'm ready to implement the native Carbon/Cocoa solution there, but Qt is preferred.
Or maybe I'm wrong in Mac philosophy and I should notify user in a kind another manner?

Update Growl doesn't support editor line in its notifications, does it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

人生百味 2024-11-11 03:18:18

我做到了!

#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 中几乎相同的良好行为:

  • 它不会抢走显示的焦点。 (在互联网上搜索了两周)
  • 那里的控件处理第一次用户单击,而其他窗口需要额外的单击才能激活。
  • 当该窗口被激活时,同一应用程序的其他窗口不会冒泡到前面。
  • 还有一个小问题仍然存在,但至少有一个简单的解决方法。或者甚至可以留下。

I did it!

#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
}

We get almost the same nice behavior as in Windows:

  • It does not stole focus on show. (Two weeks of searching over the Internet)
  • The controls there handle the first user click, while other windows need an extra click to activate.
  • When the window is being activated, the other windows of the same application, do not bubble up to the front.
  • And a small problem remains, but at least it has a simple workaround. Or even could be left.
够钟 2024-11-11 03:18:18

帕维尔,

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

http://growl.info/

Pavel,

Have you heard of Growl? Growl is a VERY impressive notification app that you can bundle and use with your application. Adium - a popular instant messaging app for OS X - uses it for all notifications.

http://growl.info/

请帮我爱他 2024-11-11 03:18:18

在 Mac 上试试这个:

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

try this on mac:

setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_AlwaysStackOnTop);
前事休说 2024-11-11 03:18:18

我刚刚测试了这些标志

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

,并且

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

没有用于窗口标志/掩码的 Cocoa 或 Carbon 代码。
而notifyWindow 的工作方式与Windows 或Linux 上类似。

Ive just tested these flags

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

And

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

Without Cocoa or Carbon code for window flags/masks.
And notifyWindow works like on Windows or Linux.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文