How to receive mouse wheel events with QSystemTrayIcon?
-
Hi everyone.
I am a QT beginner.
I searched for topics using the words "QSystemTrayIcon" and "wheelEvent" from the search bar of this site, but could not find a solution.
Please give me some advice.I have written a code to receive the mouse wheel event.
However, when the mouse cursor is in the MainWindow, I can receive the wheel event, but when the mouse pointer is in the system tray icon of the application, I cannot receive the event.Is there any way to fix this?
Thank you.
#ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QSystemTrayIcon> namespace Ui { class MainWindow; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow() override; protected: void wheelEvent(QWheelEvent* event) override; private: Ui::MainWindow *ui; QSystemTrayIcon* systemTrayIcon; }; #endif // MAINWINDOW_H
#include "mainwindow.h" #include "ui_mainwindow.h" #include <QDebug> #include <QTime> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); systemTrayIcon = new QSystemTrayIcon(QIcon(":/tray_icon.png")); systemTrayIcon->show(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::wheelEvent(QWheelEvent *event) { qDebug() << QTime::currentTime(); }
os: Linux Debian 10.10 64bit
Desktop Environment: LXDE
Window Manager: Openbox with lxpanel 0.10.0
QT: Qt 5.11.3
QT Creator: Qt Creator 4.8.2 based on Qt 5.11.3
qmake: QMake version 3.1 Using Qt version 5.11.3 -
Only on X11, when a tooltip is requested, the QSystemTrayIcon receives a QHelpEvent of type QEvent::ToolTip. Additionally, the QSystemTrayIcon receives wheel events of type QEvent::Wheel. These are not supported on any other platform.
https://doc.qt.io/qt-5/qsystemtrayicon.html#details