繁体   English   中英

如何使用 QML 和 PyQt5 创建微小的无标题栏通知 window

[英]How to create a tiny no titlebar notification window using QML and PyQt5

我们如何使用没有标题栏的 QML 创建一个微小的通知 window? 例如,看图片。 此通知似乎是由 GTK 创建的。

这个图片。

我们可以使用 PyQt5 和 QML 像这样创建吗

QML 是非常灵活的语言,您几乎可以创建任何您想要的东西。 在您的情况下,我会使用一些系统工具,因为它不是跨平台的并且可以按预期工作。 但是您始终可以创建一些自定义 window,例如:

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.5
import Qt.labs.platform 1.1

Window {
    visible: true
    width: 400
    height: 100

    RowLayout {
        anchors.centerIn: parent
        Button {
            text: "systray message"
            onClicked: {
                systray.showMessage("title", "message", SystemTrayIcon.Warning, 2000)
            }
        }
        Button {
            text: "custom message"
            onClicked: {
                popup.show();
            }
        }
    }

    SystemTrayIcon {
        id: systray
          visible: true
          icon.source: "qrc:/ok.png"
          icon.mask: false
    }

    Window {
        id: popup
        flags: Qt.FramelessWindowHint
        x: Screen.width - 350
        y: Screen.height - 150
        width: 300
        height: 30
        Rectangle {
            anchors.fill: parent
            color: "black"
            Text {
                anchors.centerIn: parent
                text: "Some custom message"
                color: "white"
            }
        }
        Timer {
            id: timer
            interval: 2000;
            running: false;
            repeat: false
            onTriggered: popup.close()
        }
        onVisibleChanged: {
            if(visible)
                timer.running = true;
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM