feat: 托盘图标使用 QStyle 标准图标切换状态
- 就绪/停止: SP_MediaStop (■) - 录音/识别: SP_MediaPlay (▶) 避免自定义绘制导致的黑色方块问题,使用 Qt 原生支持的 系统标准图标,跨平台兼容性好。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
3ccdff0828
commit
835b9fcdd8
@ -126,10 +126,11 @@ void MainWindow::setupTrayIcon() {
|
|||||||
trayIcon_ = new QSystemTrayIcon(this);
|
trayIcon_ = new QSystemTrayIcon(this);
|
||||||
trayIcon_->setContextMenu(trayMenu_);
|
trayIcon_->setContextMenu(trayMenu_);
|
||||||
|
|
||||||
// 使用应用窗口图标作为托盘图标,避免自定义绘制导致的黑色方块
|
// 默认状态:停止图标(SP_MediaStop)
|
||||||
trayIcon_->setIcon(windowIcon().isNull() ?
|
idleIcon_ = style()->standardIcon(QStyle::SP_MediaStop);
|
||||||
style()->standardIcon(QStyle::SP_ComputerIcon) :
|
activeIcon_ = style()->standardIcon(QStyle::SP_MediaPlay);
|
||||||
windowIcon());
|
|
||||||
|
trayIcon_->setIcon(idleIcon_);
|
||||||
trayIcon_->setToolTip("Impress Voice Input - 语音输入就绪");
|
trayIcon_->setToolTip("Impress Voice Input - 语音输入就绪");
|
||||||
trayIcon_->show();
|
trayIcon_->show();
|
||||||
|
|
||||||
@ -148,8 +149,12 @@ void MainWindow::setupTrayIcon() {
|
|||||||
void MainWindow::updateTrayIcon(const QString& status) {
|
void MainWindow::updateTrayIcon(const QString& status) {
|
||||||
if (!trayIcon_) return;
|
if (!trayIcon_) return;
|
||||||
|
|
||||||
// 根据状态设置 tooltip,图标保持统一的应用图标
|
// 录音/识别 → 播放图标,就绪/停止 → 停止图标
|
||||||
// 避免使用自定义 QPixmap(在某些平台/主题下会显示为黑色方块)
|
if (status.contains("正在录音") || status.contains("正在识别")) {
|
||||||
|
trayIcon_->setIcon(activeIcon_);
|
||||||
|
} else {
|
||||||
|
trayIcon_->setIcon(idleIcon_);
|
||||||
|
}
|
||||||
trayIcon_->setToolTip(QString("Impress Voice Input - %1").arg(status));
|
trayIcon_->setToolTip(QString("Impress Voice Input - %1").arg(status));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -56,6 +56,8 @@ private:
|
|||||||
QLabel* modelStatusLabel_;
|
QLabel* modelStatusLabel_;
|
||||||
QSystemTrayIcon* trayIcon_ = nullptr;
|
QSystemTrayIcon* trayIcon_ = nullptr;
|
||||||
QMenu* trayMenu_ = nullptr;
|
QMenu* trayMenu_ = nullptr;
|
||||||
|
QIcon idleIcon_; // SP_MediaStop — 就绪/停止
|
||||||
|
QIcon activeIcon_; // SP_MediaPlay — 录音/识别
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace impress
|
} // namespace impress
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user