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
This commit is contained in:
Graham Dawes
2019-09-02 15:35:31 +01:00
committed by Vadim Zeitlin
parent 1214676988
commit 631ce0e380

View File

@@ -19,7 +19,7 @@ public:
wxQtListWidget( wxWindow *parent, wxListBox *handler ); wxQtListWidget( wxWindow *parent, wxListBox *handler );
private: private:
void clicked( const QModelIndex &index ); void OnCurrentItemChange(QListWidgetItem *current, QListWidgetItem *previous);
void doubleClicked( const QModelIndex &index ); void doubleClicked( const QModelIndex &index );
void itemChanged(QListWidgetItem *item); void itemChanged(QListWidgetItem *item);
}; };
@@ -27,16 +27,22 @@ private:
wxQtListWidget::wxQtListWidget( wxWindow *parent, wxListBox *handler ) wxQtListWidget::wxQtListWidget( wxWindow *parent, wxListBox *handler )
: wxQtEventSignalHandler< QListWidget, wxListBox >( parent, 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::doubleClicked, this, &wxQtListWidget::doubleClicked);
connect(this, &QListWidget::itemChanged, this, &wxQtListWidget::itemChanged); 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(); wxListBox *handler = GetHandler();
if ( handler ) if ( handler )
{
const QModelIndex &index = indexFromItem(current);
handler->QtSendEvent(wxEVT_LISTBOX, index.row(), true); handler->QtSendEvent(wxEVT_LISTBOX, index.row(), true);
}
} }
void wxQtListWidget::doubleClicked( const QModelIndex &index ) void wxQtListWidget::doubleClicked( const QModelIndex &index )