qml代码
CMSystemTrayIcon {
id: trayIcon
visible: true
//onActivated: { trayMenu.showMenu(trayIcon.geometry) }
onTrigger:{ root.showNormal()}
onDoubleClick: {trayMenu.showMenu(trayIcon.geometry)}
}
头文件
#pragma once
#include <QSystemTrayIcon>
class CMSystemTrayIcon : public QSystemTrayIcon {
Q_OBJECT
Q_PROPERTY(QRect geometry READ getGeometry CONSTANT)
public:
Q_ENUM(ActivationReason)
static void RegisterType();
CMSystemTrayIcon(QObject* parent = nullptr);
QRect getGeometry() const;
signals:
void trigger();
void doubleclick();
private slots:
void onActivated(QSystemTrayIcon::ActivationReason reason);
};
Q_DECLARE_METATYPE(QSystemTrayIcon::ActivationReason)
cpp
#include "app/CMSystemTrayIcon.h"
#include <QQmlEngine>
void CMSystemTrayIcon::RegisterType() {
qRegisterMetaType<ActivationReason>("ActivationReason");
qmlRegisterType<CMSystemTrayIcon>("CM.App", 1, 0, "CMSystemTrayIcon");
}
CMSystemTrayIcon::CMSystemTrayIcon(QObject* parent)
: QSystemTrayIcon(parent) {
setIcon(QIcon(":/images/cm_logo_tray.png"));
}
QRect CMSystemTrayIcon::getGeometry() const {
return geometry();
}
void CMSystemTrayIcon::onActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::DoubleClick:
emit doubleclick();
case QSystemTrayIcon::Trigger:
emit trigger();
default:
break;
}
}
求大神帮帮忙啊 实在看不出来错误 必有酬谢
需要把激活的操作换为单双击不同的操作