But note the visibility checkbox its toggled() signal is connected to the icon's setVisible() function instead. We ensure that the application responds to user input by connecting most of the editor's input widgets (including the system tray icon) to the application's private slots. MainLayout - >addWidget(messageGroupBox) QVBoxLayout *mainLayout = new QVBoxLayout width()) Ĭonnect(showMessageButton, & QAbstractButton ::clicked, this, &Window ::showMessage) Ĭonnect(showIconCheckBox, & QAbstractButton ::toggled, trayIcon, & QSystemTrayIcon ::setVisible) Ĭonnect(iconComboBox, & QComboBox ::currentIndexChanged, this, &Window ::setIcon) Ĭonnect(trayIcon, & QSystemTrayIcon ::messageClicked, this, &Window ::messageClicked) Ĭonnect(trayIcon, & QSystemTrayIcon ::activated, this, &Window ::iconActivated) IconLabel - >setMinimumWidth(durationLabel - >sizeHint(). When constructing the editor widget, we first create the various editor elements before we create the actual system tray icon: We reimplement the QWidget::setVisible() function to update the tray icon's menu whenever the editor's appearance changes, e.g., when maximizing or minimizing the main application window.įinally, we reimplement QWidget's closeEvent() function to be able to inform the user (when closing the editor window) that the program will keep running in the system tray until the user chooses the Quit entry in the icon's context menu. Associated with the icon, we provide a menu containing the typical minimize, maximize, restore and quit actions. To check whether a system tray is present on the user's desktop, call the static QSystemTrayIcon::isSystemTrayAvailable() function. The tray icon is an instance of the QSystemTrayIcon class. ![]() The other private functions are only convenience functions provided to simplify the constructor. We implement several private slots to respond to user interaction. Void iconActivated( QSystemTrayIcon ::ActivationReason reason) ![]() Void closeEvent( QCloseEvent *event) override
0 Comments
Leave a Reply. |