Fix the systray example to only show an icon when requested

The "None" and "Custom icon" cases where using the same value for icon
type, which resulted in both options showing the application icon.

Use -1 to indicate the custom option, and treat all other options
the same.

Task-number: QTBUG-76916
Change-Id: Ib715f5d328175bd6e221b3f507087954fa542838
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Volker Hilsheimer 2019-07-05 15:35:34 +02:00
parent 0a3107dd30
commit 89984a8a61

View File

@ -160,9 +160,10 @@ void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
void Window::showMessage()
{
showIconCheckBox->setChecked(true);
QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::MessageIcon(
typeComboBox->itemData(typeComboBox->currentIndex()).toInt());
if (msgIcon == QSystemTrayIcon::NoIcon) {
int selectedIcon = typeComboBox->itemData(typeComboBox->currentIndex()).toInt();
QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::MessageIcon(selectedIcon);
if (selectedIcon == -1) { // custom icon
QIcon icon(iconComboBox->itemIcon(iconComboBox->currentIndex()));
trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon,
durationSpinBox->value() * 1000);
@ -222,7 +223,7 @@ void Window::createMessageGroupBox()
QStyle::SP_MessageBoxCritical), tr("Critical"),
QSystemTrayIcon::Critical);
typeComboBox->addItem(QIcon(), tr("Custom icon"),
QSystemTrayIcon::NoIcon);
-1);
typeComboBox->setCurrentIndex(1);
durationLabel = new QLabel(tr("Duration:"));