From eb6b660d2701254944af997da69801e867a306f3 Mon Sep 17 00:00:00 2001 From: Liam Treacy Date: Mon, 21 Jan 2019 14:04:47 +0000 Subject: [PATCH] Added setStyle method to wxListBox to allow for the proper setting of sorting and selection style of the QListWidget --- include/wx/qt/listbox.h | 1 + src/qt/listbox.cpp | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/wx/qt/listbox.h b/include/wx/qt/listbox.h index 0ffff6e51c..4b9c9c5ac1 100644 --- a/include/wx/qt/listbox.h +++ b/include/wx/qt/listbox.h @@ -90,6 +90,7 @@ protected: private: virtual void Init(); //common construction + void setStyle(long style); void UnSelectAll(); wxDECLARE_DYNAMIC_CLASS(wxListBox); diff --git a/src/qt/listbox.cpp b/src/qt/listbox.cpp index ffd6f84aa8..98595d3d7b 100644 --- a/src/qt/listbox.cpp +++ b/src/qt/listbox.cpp @@ -90,10 +90,7 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, QListWidgetItem* item; m_qtWindow = m_qtListWidget = new wxQtListWidget( parent, this ); - if ( style == wxLB_SORT ) - { - m_qtListWidget->setSortingEnabled(true); - } + setStyle(style); while ( n-- > 0 ) { @@ -120,6 +117,8 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, Init(); m_qtWindow = m_qtListWidget = new wxQtListWidget( parent, this ); + setStyle(style); + QStringList items; for (size_t i = 0; i < choices.size(); ++i) @@ -130,6 +129,27 @@ bool wxListBox::Create(wxWindow *parent, wxWindowID id, return wxListBoxBase::Create( parent, id, pos, size, style, validator, name ); } +void wxListBox::setStyle(long style) +{ + if ( style & wxLB_SORT ) + { + m_qtListWidget->setSortingEnabled(true); + } + + if ( style & wxLB_SINGLE ) + { + m_qtListWidget->setSelectionMode(QAbstractItemView::SingleSelection); + } + else if ( style & wxLB_MULTIPLE ) + { + m_qtListWidget->setSelectionMode(QAbstractItemView::MultiSelection); + } + else if ( style & wxLB_EXTENDED ) + { + wxMISSING_IMPLEMENTATION( wxSTRINGIZE( wxLB_EXTENDED )); + } +} + void wxListBox::Init() { #if wxUSE_CHECKLISTBOX