Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch QComboBox popup close event

A am using QComboBox derived class to show my items. My combo box is read only. But how can I catch the event when popup view of combo box closes?.
For example, when user clicks a mouse button somewhere out of my combo box?
Thank you very much in advance.

like image 277
pau Avatar asked Oct 16 '25 02:10

pau


1 Answers

What for do you want this event? If the QComboBox closes without selection nothing changed. The signals given will only be activated when a selection has been made.

If you insist on reading a "close-event", you could subclass focusOutEvent(QFocusEvent*) or use an event handler for the focus out event and emit a custom signal. Eventually you want to have a boolean flag set on hadEditFocus() before, so you can see if the dropdown would be opened.

Edit: Eventually it would be easier to subclass and reimplement showPopup() and hidePopup() as:

void MyClass::showPopup() 
{
  QComboBox::showPopup();
  emit signalPopupShown();
}

void MyClass::hidePopup()
{
  QComboBox::hidePopup();
  emit signalPopupHidden();
}

but I am not sure if hidePopup() gets called on focus-loose.

like image 92
Sebastian Lange Avatar answered Oct 17 '25 23:10

Sebastian Lange



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!