Skip to content

Instantly share code, notes, and snippets.

@kviktor
Last active October 10, 2020 14:36
Show Gist options
  • Save kviktor/976c47b63773400f7fb9d1b6ea159f95 to your computer and use it in GitHub Desktop.
Save kviktor/976c47b63773400f7fb9d1b6ea159f95 to your computer and use it in GitHub Desktop.
QT SystemTrayIcon onActivated not working
import QtQuick 2.8
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.1
import Qt.labs.platform 1.0
import QtQuick.Dialogs 1.2
ApplicationWindow {
id: appWindow
width: 50
height: 50
visible: true
title: "test"
onClosing: {
close.accepted = false;
this.visible = false;
}
SystemTrayIcon {
id: tray
visible: true
iconSource: "icon.png"
iconName: "icon name"
tooltip: "tooltip"
menu: Menu {
id: menu
Menu {
title: "menu again"
enabled: true
MenuItem {
text: "number 1"
}
MenuItem {
text: "number 2"
}
}
MenuItem {
text: "Exit"
onTriggered: {
Qt.quit();
}
}
}
onActivated: {
// this should not be undefined
// https://doc.qt.io/qt-5/qml-qt-labs-platform-systemtrayicon.html#activated-signal
console.log(reason);
}
}
}
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtWidgets import QApplication
if __name__ == "__main__":
qapplication = QApplication(sys.argv)
qapplication.setQuitOnLastWindowClosed(False)
qwindow = QQmlApplicationEngine()
qml_url = QUrl("app.qml")
qwindow.load(qml_url)
qapplication.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment