Events delivered to disabled buttons
-
Hey there,
I have the following problem. I create a group of QPushButtons. One is enabled and the others are disabled.
When I click the enabled button a processing starts, which takes a few seconds. After the processing is finished
I disable the current enabled button and enable the next button in a row.If I click now the second (disabled) button before the processing returns, then the click will be delivered to the second button after it is enabled.
I tried connect() with Qt::AutoConnection and Qt::DirectConnection, but in both cases I saw the same behaviour.
I was expecting that the click to the second (disabled) will be lost, but it is not.
Has anybody an idea what I did wrong? Is this is a bug (I'm using a self compiled 4.7.2)
Best,
Pft -
Sorry, for me your explanation is a litle confused!
-
Hi! Is the picture like : you press first button -> your app starts processing and your gui freezes, in this frozen state you click on second button and once your gui unfreezes back the second button receives click event ?
-
If you call a lengthy function from the first button's clicked() signal, the GUI will freeze, because no event dispatching can happen until the slot (from which you called the lengthy calculation) returned. Thus the click on the second button cannot be processed, until the slot returns and event dispatching continues. However at that time you already have enabled the second button! As a quick hack, you could insert a qApp()->processEvents() after your lengthy calculation has been completed and right before you enable the second button. This makes sure that all pending events get processed while the button is still disabled. The "proper" solution, however, is to put your lengthy calculations into a background thread, so event processing can continue (and the GUI doesn't freeze), while your calculation is running. Blocking the GUI with long calculation is never a good idea...
-
Hi,
sorry for the confusion guys. Meantime I found the reason for this effect. I blocked the event processing to the background by mistake. Once the lengthy action returned the event processing continued and then the event was deliverd. Definitely my fault. Thank you very much for your support.Regards,
PfT.