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?
Forum Updated to NodeBB v4.3 + New Features

How to receive mouse wheel events with QSystemTrayIcon?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 350 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.
  • N Offline
    N Offline
    namako
    wrote on 31 Aug 2021, 14:19 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
    • J Offline
      J Offline
      JoeCFD
      wrote on 31 Aug 2021, 14:27 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

      N 1 Reply Last reply 31 Aug 2021, 14:32
      1
      • J JoeCFD
        31 Aug 2021, 14:27

        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

        N Offline
        N Offline
        namako
        wrote on 31 Aug 2021, 14:32 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

        3/3

        31 Aug 2021, 14:32

        • Login

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