如何使用 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;
        }
    }
}