From 631ce0e380d8222bcf9712fdaf7f622e6b38b485 Mon Sep 17 00:00:00 2001 From: Graham Dawes Date: Mon, 2 Sep 2019 15:35:31 +0100 Subject: [PATCH] Send events when items are selected from keyboard in wxListBox Handle selection rather than clicks in wxListBox in wxQt to allow keyboard interactions to generate events. Closes https://github.com/wxWidgets/wxWidgets/pull/1526 --- src/qt/listbox.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/qt/listbox.cpp b/src/qt/listbox.cpp index a704c60f0f..1408f6f9d2 100644 --- a/src/qt/listbox.cpp +++ b/src/qt/listbox.cpp @@ -19,7 +19,7 @@ public: wxQtListWidget( wxWindow *parent, wxListBox *handler ); private: - void clicked( const QModelIndex &index ); + void OnCurrentItemChange(QListWidgetItem *current, QListWidgetItem *previous); void doubleClicked( const QModelIndex &index ); void itemChanged(QListWidgetItem *item); }; @@ -27,16 +27,22 @@ private: wxQtListWidget::wxQtListWidget( wxWindow *parent, wxListBox *handler ) : wxQtEventSignalHandler< QListWidget, wxListBox >( parent, handler ) { - connect(this, &QListWidget::clicked, this, &wxQtListWidget::clicked); + connect(this, &QListWidget::currentItemChanged, this, &wxQtListWidget::OnCurrentItemChange); connect(this, &QListWidget::doubleClicked, this, &wxQtListWidget::doubleClicked); connect(this, &QListWidget::itemChanged, this, &wxQtListWidget::itemChanged); } -void wxQtListWidget::clicked(const QModelIndex &index ) +void wxQtListWidget::OnCurrentItemChange(QListWidgetItem *current, QListWidgetItem *) { + if ( !current ) + return; + wxListBox *handler = GetHandler(); if ( handler ) + { + const QModelIndex &index = indexFromItem(current); handler->QtSendEvent(wxEVT_LISTBOX, index.row(), true); + } } void wxQtListWidget::doubleClicked( const QModelIndex &index )