System Tray Icon Example bug if I change the current icon index to 0
-
wrote on 25 Oct 2021, 10:21 last edited by
Hi Guys!
I have a problem in the System Tray Icon Example in qt.
If I change this row:iconComboBox->setCurrentIndex(1);
to:
iconComboBox->setCurrentIndex(0);
after this i have an error message in the debug:
"QSystemTrayIcon::setVisible: No Icon set"
And i dont see the icon in the tray menu, but if i set the default index to 1 as the original example, its working.
But Why? I dont understand what is the different between the 0. QComboBox icon and the 1. one?
Thanks your help! -
@Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:
connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?
wrote on 25 Oct 2021, 11:57 last edited by JonB@Kaguro
If you have code which you want run onQComboBox::currentIndexChanged
but also for the initial situation, it is easiest to call it explicitly when you start.Alternatively
QComboBox::::currentIndex()
starts at -1 on an empty combo box. If you have your signal connected before you populate it you should get the signal as it moves from -1 to 0 when you add the first item into the combo. -
Hi Guys!
I have a problem in the System Tray Icon Example in qt.
If I change this row:iconComboBox->setCurrentIndex(1);
to:
iconComboBox->setCurrentIndex(0);
after this i have an error message in the debug:
"QSystemTrayIcon::setVisible: No Icon set"
And i dont see the icon in the tray menu, but if i set the default index to 1 as the original example, its working.
But Why? I dont understand what is the different between the 0. QComboBox icon and the 1. one?
Thanks your help!wrote on 25 Oct 2021, 11:10 last edited by Pl45m4@Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:
I dont understand what is the different between the 0. QComboBox icon and the 1. one?
This line
connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
and the corresponding function
void Window::setIcon(int index) { QIcon icon = iconComboBox->itemIcon(index); trayIcon->setIcon(icon); setWindowIcon(icon); trayIcon->setToolTip(iconComboBox->itemText(index)); }
The item at index 0 probably has no icon.Edit:
Icon 0 should be the "bad" icon... Do you see that icon in your combobox and are you able to select it manually?
iconComboBox = new QComboBox; iconComboBox->addItem(QIcon(":/images/bad.png"), tr("Bad")); iconComboBox->addItem(QIcon(":/images/heart.png"), tr("Heart")); iconComboBox->addItem(QIcon(":/images/trash.png"), tr("Trash"));
-
@Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:
I dont understand what is the different between the 0. QComboBox icon and the 1. one?
This line
connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
and the corresponding function
void Window::setIcon(int index) { QIcon icon = iconComboBox->itemIcon(index); trayIcon->setIcon(icon); setWindowIcon(icon); trayIcon->setToolTip(iconComboBox->itemText(index)); }
The item at index 0 probably has no icon.Edit:
Icon 0 should be the "bad" icon... Do you see that icon in your combobox and are you able to select it manually?
iconComboBox = new QComboBox; iconComboBox->addItem(QIcon(":/images/bad.png"), tr("Bad")); iconComboBox->addItem(QIcon(":/images/heart.png"), tr("Heart")); iconComboBox->addItem(QIcon(":/images/trash.png"), tr("Trash"));
wrote on 25 Oct 2021, 11:35 last edited by@Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:
connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?
-
@Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:
connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?
wrote on 25 Oct 2021, 11:57 last edited by JonB@Kaguro
If you have code which you want run onQComboBox::currentIndexChanged
but also for the initial situation, it is easiest to call it explicitly when you start.Alternatively
QComboBox::::currentIndex()
starts at -1 on an empty combo box. If you have your signal connected before you populate it you should get the signal as it moves from -1 to 0 when you add the first item into the combo. -
@Kaguro
If you have code which you want run onQComboBox::currentIndexChanged
but also for the initial situation, it is easiest to call it explicitly when you start.Alternatively
QComboBox::::currentIndex()
starts at -1 on an empty combo box. If you have your signal connected before you populate it you should get the signal as it moves from -1 to 0 when you add the first item into the combo. -
@Pl45m4 said in System Tray Icon Example bug if I change the current icon index to 0:
connect(iconComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &Window::setIcon);
Yes I see the icon in my combobox and i can select it manually. One mention: Is there any chance the currentIndexChanged event is the issue? Because the default index is 0 in combobox, and if i want to use the 0. index the "currentIndexChanged" event is not execute because i didnt changed the index?
wrote on 25 Oct 2021, 12:03 last edited by@Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:
Is there any chance the currentIndexChanged event is the issue?
The signal even gets emitted when you change the idex programmatically.
So something else must be wrong or you are doing something else wrong.
-
@Kaguro said in System Tray Icon Example bug if I change the current icon index to 0:
Is there any chance the currentIndexChanged event is the issue?
The signal even gets emitted when you change the idex programmatically.
So something else must be wrong or you are doing something else wrong.
wrote on 25 Oct 2021, 12:26 last edited by@Pl45m4
I'm only guessing for the OP, but looking https://doc.qt.io/qt-5/qtwidgets-desktop-systray-example.html#window-class-implementation theconnect(iconComboBox, &QComboBox::currentIndexChanged)
gets executed aftericonComboBox
gets populated? So if he wants it to be called initially he needs to do either of what I suggested? -
@Pl45m4
I'm only guessing for the OP, but looking https://doc.qt.io/qt-5/qtwidgets-desktop-systray-example.html#window-class-implementation theconnect(iconComboBox, &QComboBox::currentIndexChanged)
gets executed aftericonComboBox
gets populated? So if he wants it to be called initially he needs to do either of what I suggested?wrote on 25 Oct 2021, 12:38 last edited byI dont think it's necessary, because
iconComboBox->setCurrentIndex(1 /* or 0 */);
is called after the connection was set up and the combobox was filled.
Then it should emitcurrentIndexChanged
anyways... but I could be wrong :)(You would face the same situation when you add items to your comboBox in Design-Mode. The items are there, before you make any connections to your instances.
setupUI
would create the items and this is usually called first in any c'tor) -
I dont think it's necessary, because
iconComboBox->setCurrentIndex(1 /* or 0 */);
is called after the connection was set up and the combobox was filled.
Then it should emitcurrentIndexChanged
anyways... but I could be wrong :)(You would face the same situation when you add items to your comboBox in Design-Mode. The items are there, before you make any connections to your instances.
setupUI
would create the items and this is usually called first in any c'tor)wrote on 25 Oct 2021, 12:41 last edited by JonB@Pl45m4
I have not tested this, and you may know more than I. But after the initial population thecurrentIndex
will already be on0
, only then is theconnect()
executed. TheniconComboBox->setCurrentIndex(0)
will not raisecurrentIndexChanged
signal, and so not call the slot, but he wants it to be called, which I am assuming is the OP's situation?Your design-mode description is indeed correct, and in this case again
currentIndexChanged
slots will not be called. -
@Pl45m4
I have not tested this, and you may know more than I. But after the initial population thecurrentIndex
will already be on0
, only then is theconnect()
executed. TheniconComboBox->setCurrentIndex(0)
will not raisecurrentIndexChanged
signal, and so not call the slot, but he wants it to be called, which I am assuming is the OP's situation?Your design-mode description is indeed correct, and in this case again
currentIndexChanged
slots will not be called.wrote on 25 Oct 2021, 13:25 last edited by@JonB said in System Tray Icon Example bug if I change the current icon index to 0:
Then iconComboBox->setCurrentIndex(0) will not raise currentIndexChanged signal, and so not call the slot, but he wants it to be called, which I am assuming is the OP's situation?
Yes, now I understand what you meant before :)
1/10