tray latest
Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu and notifications.
QtTrayMenu Class Reference

Wrapper class for platfrom-independent Qt-based tray menu. More...

#include <src/QtTrayMenu.h>

Inheritance diagram for QtTrayMenu:
[legend]
Collaboration diagram for QtTrayMenu:
[legend]

Signals

void exit ()
 Exit tray and cleanup resources.
 
void showMenu () const
 Show tray context menu.
 
void update (struct tray *tray, bool notify=true)
 Update tray configuration.
 

Public Member Functions

void clickMenuItem (int index) const
 Simulate click on menu item.
 
void clickMessage () const
 Simulate click on popup message.
 
void configureAppMetadata (const QString &appName, const QString &appDisplayName, const QString &desktopName) const
 Configure metadata for QApplication.
 
bool eventFilter (QObject *watched, QEvent *event) override
 QObject override to filter events on watched object.
 
int init (struct tray *tray, bool notification=true)
 Initialize tray with given structure.
 
int loop (int blocking)
 Process tray loop events.
 
 QtTrayMenu (int argc, char **argv, QObject *parent=nullptr, bool debug=false)
 Create a QtTrayMenu instance.
 
 QtTrayMenu (QObject *parent=nullptr, bool debug=false)
 Create a QtTrayMenu instance.
 
void showMessage (const QString &title, const QString &msg, const QString &iconPath, std::function< void()> callback=nullptr, int msecs=10000)
 Show tray message popup.
 
void showMessage (const QString &title, const QString &msg, std::function< void()> callback=nullptr, QSystemTrayIcon::MessageIcon icon=QSystemTrayIcon::Information, int msecs=10000)
 Show tray message popup.
 

Static Public Member Functions

static bool supportsMessages ()
 Check if QtTrayMenu supports messages.
 

Detailed Description

Wrapper class for platfrom-independent Qt-based tray menu.

Constructor & Destructor Documentation

◆ QtTrayMenu() [1/2]

QtTrayMenu::QtTrayMenu ( QObject * parent = nullptr,
bool debug = false )
explicit

Create a QtTrayMenu instance.

Parameters
parentoptional parent Qt object
debugif true isntall eventFilter for debug logging

◆ QtTrayMenu() [2/2]

QtTrayMenu::QtTrayMenu ( int argc,
char ** argv,
QObject * parent = nullptr,
bool debug = false )
explicit

Create a QtTrayMenu instance.

Parameters
argcargument count for QApplication (if that needs to be created)
argvargument list for QApplication (if that needs to be created)
parentoptional parent Qt object
debugif true isntall eventFilter for debug logging

Member Function Documentation

◆ clickMenuItem()

void QtTrayMenu::clickMenuItem ( int index) const

Simulate click on menu item.

Parameters
indexMenu item index to simulate click on

◆ configureAppMetadata()

void QtTrayMenu::configureAppMetadata ( const QString & appName,
const QString & appDisplayName,
const QString & desktopName ) const

Configure metadata for QApplication.

Parameters
appNamethe applications name
appDisplayNamethe applications display name
desktopNamethe applications desktop file name

◆ eventFilter()

bool QtTrayMenu::eventFilter ( QObject * watched,
QEvent * event )
override

QObject override to filter events on watched object.

Parameters
watchedobject watched for event
eventevent on object
Returns
true if event should be filtered out and not be processed further
See also
https://doc.qt.io/qt-6/qobject.html#eventFilter

◆ init()

int QtTrayMenu::init ( struct tray * tray,
bool notification = true )

Initialize tray with given structure.

Parameters
traystruct containing tray configuration
notificationfire tray notification if true
Returns
0 on success

◆ loop()

int QtTrayMenu::loop ( int blocking)

Process tray loop events.

Parameters
blockingif true the function call will block until QtTrayMenu exits
Returns
0 on successful processing if non-blocking, -1 otherwise

◆ showMessage() [1/2]

void QtTrayMenu::showMessage ( const QString & title,
const QString & msg,
const QString & iconPath,
std::function< void()> callback = nullptr,
int msecs = 10000 )

Show tray message popup.

Parameters
titlepopup title
msgpopup message
callbacktray message callback function
iconPathpopup icon file path
msecspopup display duration

◆ showMessage() [2/2]

void QtTrayMenu::showMessage ( const QString & title,
const QString & msg,
std::function< void()> callback = nullptr,
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information,
int msecs = 10000 )

Show tray message popup.

Parameters
titlepopup title
msgpopup message
callbacktray message callback function
iconpopup icon
msecspopup display duration

◆ supportsMessages()

bool QtTrayMenu::supportsMessages ( )
static

Check if QtTrayMenu supports messages.

Returns
true if messages can be shown

◆ update

void QtTrayMenu::update ( struct tray * tray,
bool notify = true )
signal

Update tray configuration.

Parameters
traystruct containing tray configuration
notifyfire tray notification if true

The documentation for this class was generated from the following files: