Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to receive mouse wheel events with QSystemTrayIcon?

How to receive mouse wheel events with QSystemTrayIcon?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 346 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • namakoN Offline
    namakoN Offline
    namako
    wrote on last edited by namako
    #1

    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

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      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

      namakoN 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        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

        namakoN Offline
        namakoN Offline
        namako
        wrote on last edited by
        #3

        @JoeCFD Thanks for the reply.
        I understand now.
        I'll try it soon.
        Thank you for your kindness and clear explanation.
        (^_^)

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved