Avoid focus loss event when wxComboBox popup is opened in wxQt

Prevent wxComboBox from generating a wxEVT_KILL_FOCUS event when the
user opens the drop-down list under wxQt, as logically the drop-down is
part of wxComboBox, even if it's a separate window at Qt level.

Closes https://github.com/wxWidgets/wxWidgets/pull/1377
This commit is contained in:
Graham Dawes
2019-07-01 08:20:05 +01:00
committed by Vadim Zeitlin
parent 1c5921f85a
commit 9e35bb92c0
2 changed files with 20 additions and 0 deletions

View File

@@ -80,6 +80,7 @@ public:
virtual void Popup();
virtual void Dismiss();
virtual bool QtHandleFocusEvent(QWidget *handler, QFocusEvent *event) wxOVERRIDE;
protected:
// From wxTextEntry:

View File

@@ -15,6 +15,9 @@
#include <QtWidgets/QComboBox>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QApplication>
#include <QtWidgets/QAbstractItemView>
#include <QtGui/QFocusEvent>
class wxQtComboBox : public wxQtEventSignalHandler< QComboBox, wxComboBox >
{
@@ -254,6 +257,22 @@ void wxComboBox::Dismiss()
static_cast<QComboBox *>(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() )