QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
TrayIcon Class Reference

Handles the system tray icon and menu. More...

#include <trayicon.h>

Inheritance diagram for TrayIcon:
Collaboration diagram for TrayIcon:

Public Slots

void showHideParent ()
 Toggle the visibility of the associated main window.
void iconActivated (QSystemTrayIcon::ActivationReason reason)
 Handle activation events from the system tray icon.

Public Member Functions

 TrayIcon (QMainWindow *parent)
 Construct a TrayIcon associated with the given main window.
auto getIsAllocated () -> bool
 Check whether tray resources have been allocated and initialized.
void addToggle (QAction *action)
 Put one of the window's toggles in the tray menu, above Quit.

Private Member Functions

void createActions ()
 Create the Show/Hide/Minimize/Maximize/Restore/Quit actions and wire each one to the matching QWidget slot of the main window (Quit goes to QApplication::quit()).
void createTrayIcon ()
 Build the context menu from the actions and create the QSystemTrayIcon that pops it up. Called only when a system tray is available.

Private Attributes

QAction * showAction {nullptr}
 Shows the main window (QWidget::show()).
QAction * hideAction {nullptr}
 Hides the main window (QWidget::hide()).
QAction * minimizeAction {nullptr}
 Minimises the main window.
QAction * maximizeAction {nullptr}
 Maximises the main window.
QAction * restoreAction {nullptr}
 Restores the main window to its normal size.
QAction * quitAction {nullptr}
 Quits the application.
QAction * quitSeparator {nullptr}
 Separator directly above Quit; addToggle() inserts the window's toggles (each with its own separator) in front of it.
QSystemTrayIcon * sysTrayIcon {nullptr}
 The icon in the notification area; owned by this object so it is destroyed, and the icon removed, when the main window goes away. Null when no system tray is available.
QMenu * trayIconMenu {nullptr}
 Context menu of the tray icon; a child of the main window because QMenu needs a widget parent. Null when no system tray is available.
QMainWindow * parentwin
 The main window the actions and showHideParent() operate on.
bool isAllocated {false}
 true once the actions, menu and icon exist; stays false when QSystemTrayIcon::isSystemTrayAvailable() was false at construction.

Detailed Description

Handles the system tray icon and menu.

A QObject parented to the main window: nothing here is a widget (the menu and the QSystemTrayIcon are children of this object), and the parent makes sure ~QSystemTrayIcon runs on quit, which is what removes the icon from the notification area on Windows.

Definition at line 28 of file trayicon.h.

Constructor & Destructor Documentation

◆ TrayIcon()

TrayIcon::TrayIcon ( QMainWindow * parent)
explicit

Construct a TrayIcon associated with the given main window.

Parameters
parentPointer to the QMainWindow this tray icon controls.

Definition at line 16 of file trayicon.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ addToggle()

void TrayIcon::addToggle ( QAction * action)

Put one of the window's toggles in the tray menu, above Quit.

Parameters
actionThe window's own action, so its checked state is the same in both places. Ignored when there is no tray.

Definition at line 76 of file trayicon.cpp.

Here is the caller graph for this function:

◆ createActions()

void TrayIcon::createActions ( )
private

Create the Show/Hide/Minimize/Maximize/Restore/Quit actions and wire each one to the matching QWidget slot of the main window (Quit goes to QApplication::quit()).

Definition at line 40 of file trayicon.cpp.

Here is the caller graph for this function:

◆ createTrayIcon()

void TrayIcon::createTrayIcon ( )
private

Build the context menu from the actions and create the QSystemTrayIcon that pops it up. Called only when a system tray is available.

Definition at line 60 of file trayicon.cpp.

Here is the caller graph for this function:

◆ getIsAllocated()

auto TrayIcon::getIsAllocated ( ) -> bool

Check whether tray resources have been allocated and initialized.

Returns
true if tray resources are allocated and initialized.

Definition at line 38 of file trayicon.cpp.

Here is the caller graph for this function:

◆ iconActivated

void TrayIcon::iconActivated ( QSystemTrayIcon::ActivationReason reason)
slot

Handle activation events from the system tray icon.

Parameters
reasonThe activation reason provided by QSystemTrayIcon.

Definition at line 92 of file trayicon.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ showHideParent

void TrayIcon::showHideParent ( )
slot

Toggle the visibility of the associated main window.

Definition at line 84 of file trayicon.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ hideAction

QAction* TrayIcon::hideAction {nullptr}
private

Hides the main window (QWidget::hide()).

Definition at line 83 of file trayicon.h.

◆ isAllocated

bool TrayIcon::isAllocated {false}
private

true once the actions, menu and icon exist; stays false when QSystemTrayIcon::isSystemTrayAvailable() was false at construction.

Definition at line 117 of file trayicon.h.

◆ maximizeAction

QAction* TrayIcon::maximizeAction {nullptr}
private

Maximises the main window.

Definition at line 87 of file trayicon.h.

◆ minimizeAction

QAction* TrayIcon::minimizeAction {nullptr}
private

Minimises the main window.

Definition at line 85 of file trayicon.h.

◆ parentwin

QMainWindow* TrayIcon::parentwin
private

The main window the actions and showHideParent() operate on.

Definition at line 111 of file trayicon.h.

◆ quitAction

QAction* TrayIcon::quitAction {nullptr}
private

Quits the application.

Definition at line 91 of file trayicon.h.

◆ quitSeparator

QAction* TrayIcon::quitSeparator {nullptr}
private

Separator directly above Quit; addToggle() inserts the window's toggles (each with its own separator) in front of it.

Definition at line 96 of file trayicon.h.

◆ restoreAction

QAction* TrayIcon::restoreAction {nullptr}
private

Restores the main window to its normal size.

Definition at line 89 of file trayicon.h.

◆ showAction

QAction* TrayIcon::showAction {nullptr}
private

Shows the main window (QWidget::show()).

Definition at line 81 of file trayicon.h.

◆ sysTrayIcon

QSystemTrayIcon* TrayIcon::sysTrayIcon {nullptr}
private

The icon in the notification area; owned by this object so it is destroyed, and the icon removed, when the main window goes away. Null when no system tray is available.

Definition at line 103 of file trayicon.h.

◆ trayIconMenu

QMenu* TrayIcon::trayIconMenu {nullptr}
private

Context menu of the tray icon; a child of the main window because QMenu needs a widget parent. Null when no system tray is available.

Definition at line 109 of file trayicon.h.


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