- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 Ubuntu 12.04,虽然我可以创建一个带有可用菜单的托盘图标,但我无法控制它的操作:
trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(QIcon(":/icons/Pictures/icon.png"));
trayIcon->setToolTip(QString("Hello there..."));
connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(clickSysTrayIcon(QSystemTrayIcon::ActivationReason)));
connect(this,SIGNAL(minimized()),this,SLOT(hide()),Qt::QueuedConnection);
QMenu *changer_menu = new QMenu;
Show_action = new QAction(tr("S&how"),this);
Show_action->setIconVisibleInMenu(true);
connect(Show_action, SIGNAL(triggered()), this, SLOT(showClicked()));
changer_menu->addAction(Show_action);
changer_menu->addSeparator();
Quit_action = new QAction(tr("&Quit"), this);
Quit_action->setIconVisibleInMenu(true);;
connect(Quit_action, SIGNAL(triggered()), this, SLOT(close_minimize()));
changer_menu->addAction(Quit_action);
trayIcon->setContextMenu(changer_menu);
trayIcon->show();
clickSysTrayIcon(QSystemTrayIcon::ActivationReason) 如下:
void MainWindow::clickSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
//reason is a variable that holds the type of activation or click done on the icon tray
qDebug() << "I'm in!";
}
并且,在头文件中定义为:
private Q_SLOTS:
void clickSysTrayIcon(QSystemTrayIcon::ActivationReason reason);
但是,我无法获得“我加入了!”要显示的消息。我试图让它与左/右单击、中键单击和鼠标滚轮一起工作,但我从未看到此消息被输出。
怎么了?
编辑:特定系统 Ubuntu 12.04 似乎有问题,因为它不再使用托盘图标,而只使用指示器。因此,有一个程序使用托盘图标并将它们转换为指示器。但是,指标的特征就没有了。我知道这应该归咎于系统,因为同一个程序,在完全相同的代码下,在 Lubuntu 12.04 和 LXDE 桌面下完美运行。
我为此责怪 Ubuntu。 sni-qt 包不能很好地从托盘图标迁移到指示器,前提是指示器可以通过点击、滚轮等进行交互。真可惜!这个问题有什么解决办法吗?
我的赏金结束了,所以如果有人可以解决这个问题,我将不胜感激!
最佳答案
向对项目影响最大的人提出问题。
https://help.ubuntu.com/community/ReportingBugs#How_to_report_bugs
我会在绘制指示器的指示器区域顶部制作一个 float 的无框 qwidget,然后在其上添加适当的 mouseEvent 函数。
这是这种变通方法的起点。我不知道这是怎么回事,但它在 Windows 中运行良好。我知道有一些适用于 Windows 的 UI 调整和工具使用这种分层元素样式,例如 DisplayFusion 和 TeamViewer。我还没有在 Ubuntu 中测试它,但它应该以同样的方式工作。
#include <QtGui/QWidget>
#include <QMenu>
#include <QSystemTrayIcon>
#include <QMouseEvent>
#include <QPixmap>
#include <QAction>
#include <QDebug>
#include <QPaintEvent>
#include <QPainter>
#include <QApplication>
#include <QTimerEvent>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0)
: QWidget(parent)
{
// setup this widget to be borderless, transparent around the image
// and always on top
// and not to have a presence in the "visible window list"
this->setWindowFlags( Qt::WindowStaysOnTopHint |
Qt::FramelessWindowHint | Qt::Tool);
this->setAttribute(Qt::WA_TranslucentBackground);
// necessary if you want to track when you enter and leave the widget's rect with the mouse
this->setMouseTracking(true);
m_trayIcon = new QSystemTrayIcon(this);
m_trayIcon->setIcon(QIcon("icon1.ico"));
m_trayIcon->setToolTip(QString("Hello there..."));
m_changer_menu = new QMenu;
m_show_action = new QAction(tr("S&how"),this);
m_show_action->setIconVisibleInMenu(true);
connect(m_show_action, SIGNAL(triggered()), this, SLOT(showClicked()));
m_changer_menu->addAction(m_show_action);
m_changer_menu->addSeparator();
m_quit_action = new QAction(tr("&Quit"), this);
m_quit_action->setIconVisibleInMenu(true);;
connect(m_quit_action, SIGNAL(triggered()), this, SLOT(close_minimize()));
m_changer_menu->addAction(m_quit_action);
m_trayIcon->setContextMenu(m_changer_menu);
m_trayIcon->show();
QPixmap p("icon2.ico");
m_pix = p.scaled(QSize(m_trayIcon->geometry().width(),
m_trayIcon->geometry().height()),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
this->move(m_trayIcon->geometry().x() ,m_trayIcon->geometry().y());
this->resize(m_trayIcon->geometry().width(), m_trayIcon->geometry().height());
// qDebug() << m_trayIcon->geometry();
// qDebug() << this->geometry();
// This assumes that the notification is stationary. If you want it to move
// with the tray icon underneath, you will need to subclass QSystemTrayIcon
// and track its move and resize and probably also its show and hide events
// raise itself 15x a second
this->startTimer(1000/15);
}
~Widget(){ }
public slots:
void mouseDoubleClickEvent(QMouseEvent *)
{
qDebug() << Q_FUNC_INFO;
}
void mouseReleaseEvent(QMouseEvent * me)
{
qDebug() << Q_FUNC_INFO;
switch(me->button())
{
case Qt::LeftButton:
qDebug() << "Left Click";
break;
case Qt::RightButton:
qDebug() << "Right Click";
m_changer_menu->popup(this->geometry().topLeft() + me->pos());
break;
default:
qDebug() << "other click";
break;
}
}
void showClicked()
{
qDebug() << Q_FUNC_INFO;
}
void close_minimize()
{
qDebug() << Q_FUNC_INFO;
qApp->exit();
}
void paintEvent(QPaintEvent *)
{
QPainter aPainter(this);
aPainter.drawPixmap(rect(), m_pix);
}
void timerEvent(QTimerEvent *)
{
if(!m_changer_menu->isVisible())
this->raise();
}
private:
QPixmap m_pix;
QSystemTrayIcon * m_trayIcon;
QMenu * m_changer_menu;
QAction * m_quit_action;
QAction * m_show_action;
};
这是主要功能...
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
关于qt - 由于激活原因,无法使 QSystemTrayIcon 正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11562319/
使用 Kubuntu 18.04 (qt5 5.9.5)、Python 3.6。我无法让此代码显示托盘图标;显示了 Dropbox 等其他图标,但这不是: import sys from PyQt5.
正如标题所说,如果我制作一个系统托盘图标,它可以选择通过那里打开另一个对话框(例如首选项),当我关闭另一个对话框时,整个应用程序将在我调用时关闭这个>关闭();从那个首选项对话框。拿这个例子代码: m
我已将 QSystemTrayIcon::ActivationReason 连接到我的“handleClick”插槽,如下所示 connect(tray,SIGNAL(activated(QSyste
有类似的问题,但他们没有解决我的问题。 我只有一个简单的 MainWindow 类,它会在启动时显示。构造函数包含以下代码: QWidget* centralWidget = new QWidget(
使用 QSystemTrayIcon 对象,我如何确定它当前是否被单击?另外,我如何确定用户何时单击了托盘图标及其关联菜单?我认为这涉及安装事件过滤器? 我想显示 UI,但我只想在托盘图标当前未激活时
我正在创建托盘图标应用程序,我想创建高级上下文菜单,如下图所示,但我只知道如何创建简单的菜单 QMenu* menu = new QMenu() menu->addAction(QIcon(), "i
如何在QSystemTrayIcon的消息显示时禁用或启用声音?它必须只启用或禁用消息的声音。谢谢... 最佳答案 您必须自己发出通知,因为 Qt 不提供此类功能(如果我们谈论的是 QSystemTr
当我运行并退出我的应用程序时,它会在托盘中留下太多托盘图标,而不是只有一个。我还设置了我的应用程序,因此一次只能实例化一个实例,但在程序启动和退出几次后,系统托盘似乎容纳了所有图标,当我将鼠标悬停在它
我有一个名为 StatusIcon 的类,它扩展了 QSystemTrayIcon。我想设置它,所以右键单击打开上下文菜单,左键单击打开一个窗口。 目前默认行为似乎是左键和右键单击打开上下文菜单。 我
我编写了一个小程序来在合成器(xfwm4、dcompmgr、cairo-compmgr)之间切换,以帮助解决 nVidia 可能遇到的视频撕裂问题。它在系统托盘中创建一个具有其操作的图标。问题是当我运
我有一个简单的 PyQt5 应用程序,这只是一个例子,并没有做任何事情: #!/usr/bin/env python # -*- encoding: utf-8 -*- import sys from
我曾尝试在 PySide6 文档中搜索有关 QMenu 和 QSystemTray 类的信息,但无法找到有关从函数向上下文菜单添加操作的任何信息。这是我尝试过的代码: from PySide6.QtW
import sys from PyQt5.QtWidgets import QSystemTrayIcon, QApplication, QMenu from PyQt5.QtGui import
我试图在 PyQT5 程序中单击系统托盘图标时打印文本。我尝试将 PyQT5 QSystemTrayIcon 激活信号(单击系统托盘图标时发出)连接到自定义方法,但未调用该方法。这是一个简单的例子:
我正在使用 Pyqt,但是 C++ 代码很好。我正在尝试使用 Linux (Ubuntu 11.10) 中的 QT 框架更改 QSystemTrayIcon 中的菜单项。目前我已尝试重置我最初设置的
即使正在执行activated插槽,菜单仍然没有显示。我通过手动点击托盘图标和模拟点击进行了追踪,其执行逻辑是相同的。 目前我有 class MyClass(QObject): def __in
我似乎找不到任何关于此的信息。但是很多 kde 应用程序使用动画图标。 据我所知,将 gif 设置为 QIcon 是行不通的,因为只会显示第一帧。 最佳答案 我没有尝试过,但每隔几毫秒设置一个新图标可
我正在编写应用程序,托盘类中有奇怪的错误。在我的类里面,我使用 QSystemTrayIcon 之类的 tray = new QSystemTrayIcon(this); tray->setIco
我有一个 QSystemTrayIcon 子类。在里面,我有: quitAction = new QAction(tr("&Quit"), m_parent); connect(quitAction,
我在 Mac 和 Linux 上遇到了 QSystemTrayIcon 类的问题。 我制作了一个创建系统托盘图标的程序,在 Windows 上没有问题,但在 Linux(ubuntu 12)和 Mac
我是一名优秀的程序员,十分优秀!