首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在QT中自定义"Notification“

如何在QT中自定义"Notification“
EN

Stack Overflow用户
提问于 2015-03-03 04:48:49
回答 1查看 804关注 0票数 1

我正在使用QtWebkit创建一个简单的浏览器,我设法添加了对Notification Web API it的支持,使用了QWebPage::setFeaturePermission

示例:

代码语言:javascript
运行
复制
function notifyMe() {
    if (Notification.permission === "granted") {
        var notification = new Notification("Hi there!");
    } else if (Notification.permission !== "denied") {
        Notification.requestPermission(function(permission) {
            if (permission === "granted") {
                var notification = new Notification("Hi there!");
            }
        });
    }
}

<button onclick="notifyMe();">Notify me</button>

我的代码:

代码语言:javascript
运行
复制
QObject::connect(page,
    SIGNAL(featurePermissionRequested(QWebFrame*, QWebPage::Feature)), this,
    SLOT(featurePermissionRequested(QWebFrame*,QWebPage::Feature))
);

...

void Form::featurePermissionRequested(QWebFrame* frame, QWebPage::Feature feature) {
    switch (feature) {
        case QWebPage::Notifications:
            qDebug() << "Notification";
            page->setFeaturePermission(frame, feature, QWebPage::PermissionGrantedByUser);
        break;
        case QWebPage::Geolocation:
            qDebug() << "GEO";
        break;
        default:
            qDebug() << "Unknown feature";
    }
}

每次单击“通知我”按钮时,桌面上都会出现以下消息:

可以在QT中自定义通知吗?换句话说,与GoogleChrome或火狐相似,如下所示:

EN

回答 1

Stack Overflow用户

发布于 2015-03-11 15:26:49

新通知可以采用以下两个参数:

代码语言:javascript
运行
复制
var notification = new Notification(title, options);

作为options对象的一部分,您可以传递要在通知中显示的'body‘和’图标‘。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28824296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档