diff --git a/include/wx/qt/combobox.h b/include/wx/qt/combobox.h index c5bce191de..75e8ee8852 100644 --- a/include/wx/qt/combobox.h +++ b/include/wx/qt/combobox.h @@ -80,6 +80,7 @@ public: virtual void Popup(); virtual void Dismiss(); + virtual bool QtHandleFocusEvent(QWidget *handler, QFocusEvent *event) wxOVERRIDE; protected: // From wxTextEntry: diff --git a/src/qt/combobox.cpp b/src/qt/combobox.cpp index 9189d068fa..af5846384d 100644 --- a/src/qt/combobox.cpp +++ b/src/qt/combobox.cpp @@ -15,6 +15,9 @@ #include #include +#include +#include +#include class wxQtComboBox : public wxQtEventSignalHandler< QComboBox, wxComboBox > { @@ -254,6 +257,22 @@ void wxComboBox::Dismiss() static_cast(GetHandle())->hidePopup(); } +bool wxComboBox::QtHandleFocusEvent(QWidget *handler, QFocusEvent *event) +{ + if ( !event->gotFocus() ) + { + // Qt treats the combobox and its drop-down as distinct widgets, but in + // wxWidgets they're both part of the same control, so we have to avoid + // generating a lose focus event if the combobox or its drop-down still + // have focus. + QWidget* const widget = qApp->focusWidget(); + if ( widget == m_qtComboBox || widget == m_qtComboBox->view() ) + return false; + } + + return wxChoice::QtHandleFocusEvent(handler, event); +} + void wxComboBox::Clear() { if ( !IsReadOnly() )