From 2a64b6514921b6b24e1ca4ba1d0194bcc88e8f02 Mon Sep 17 00:00:00 2001 From: Liam Treacy Date: Mon, 10 Dec 2018 11:23:50 +0000 Subject: [PATCH] Fix enabling radiobox buttons in wxQt If a QGroupBox is disabled, then you cannot set any of its items to be enabled without first enabling it. Enabling/disabling it will set that value (true/false) on all of its items, although setting the QGroupBox to an enabled state which it already has does not result in this behaviour. Fix wxQt to match the expected wxRadioBox behaviour and allow the unit test to pass. Closes https://github.com/wxWidgets/wxWidgets/pull/1064 --- include/wx/qt/radiobox.h | 9 +++++---- src/qt/radiobox.cpp | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/include/wx/qt/radiobox.h b/include/wx/qt/radiobox.h index f858a576f6..2c84083aa3 100644 --- a/include/wx/qt/radiobox.h +++ b/include/wx/qt/radiobox.h @@ -65,10 +65,11 @@ public: using wxWindowBase::Enable; using wxRadioBoxBase::GetDefaultBorder; - virtual bool Enable(unsigned int n, bool enable = true); - virtual bool Show(unsigned int n, bool show = true); - virtual bool IsItemEnabled(unsigned int n) const; - virtual bool IsItemShown(unsigned int n) const; + virtual bool Enable(unsigned int n, bool enable = true) wxOVERRIDE; + virtual bool Enable(bool enable = true) wxOVERRIDE; + virtual bool Show(unsigned int n, bool show = true) wxOVERRIDE; + virtual bool IsItemEnabled(unsigned int n) const wxOVERRIDE; + virtual bool IsItemShown(unsigned int n) const wxOVERRIDE; virtual unsigned int GetCount() const; virtual wxString GetString(unsigned int n) const; diff --git a/src/qt/radiobox.cpp b/src/qt/radiobox.cpp index 693e673170..beede99053 100644 --- a/src/qt/radiobox.cpp +++ b/src/qt/radiobox.cpp @@ -168,10 +168,42 @@ static QAbstractButton *GetButtonAt( const QButtonGroup *group, unsigned int n ) bool wxRadioBox::Enable(unsigned int n, bool enable) { - QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, n ); - CHECK_BUTTON( qtButton, false ); + if ( enable && !m_qtGroupBox->isEnabled() ) + { + m_qtGroupBox->setEnabled( true ); + + for ( unsigned int i = 0; i < GetCount(); ++i ) + { + QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, i ); + CHECK_BUTTON( qtButton, false ); + + qtButton->setEnabled( i == n ); + } + } + else + { + QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, n ); + CHECK_BUTTON( qtButton, false ); + qtButton->setEnabled(enable); + } + + return true; +} + +bool wxRadioBox::Enable( bool enable ) +{ + if ( m_qtGroupBox->isEnabled() == enable ) + { + for ( unsigned int i = 0; i < GetCount(); ++i ) + { + QAbstractButton *qtButton = GetButtonAt( m_qtButtonGroup, i ); + CHECK_BUTTON( qtButton, false ); + qtButton->setEnabled( enable ); + } + } + + m_qtGroupBox->setEnabled( enable ); - qtButton->setEnabled( enable ); return true; }