简体   繁体   English

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

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

How can we create a tiny notification window using QML without a title bar?我们如何使用没有标题栏的 QML 创建一个微小的通知 window? For example, look at the picture.例如,看图片。 This notification seems like created by GTK.此通知似乎是由 GTK 创建的。

这个图片。

can we create on like this using PyQt5 and QML我们可以使用 PyQt5 和 QML 像这样创建吗

QML is very flexible language, you can create almost whatever you want. QML 是非常灵活的语言,您几乎可以创建任何您想要的东西。 In your case I would use some system tool, since it't cross platform and works as expected.在您的情况下,我会使用一些系统工具,因为它不是跨平台的并且可以按预期工作。 But you always can create some custom window, for example:但是您始终可以创建一些自定义 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