Generate events when wxRadioButton is checked under wxQt

Closes https://github.com/wxWidgets/wxWidgets/pull/1210
This commit is contained in:
ffa-benarmstrong
2019-02-01 09:27:53 +00:00
committed by Vadim Zeitlin
parent 36fc9b3e5a
commit f930bd6740

View File

@@ -10,9 +10,32 @@
#include "wx/radiobut.h" #include "wx/radiobut.h"
#include "wx/qt/private/converter.h" #include "wx/qt/private/converter.h"
#include "wx/qt/private/winevent.h"
#include <QtWidgets/QRadioButton> #include <QtWidgets/QRadioButton>
class wxQtRadioButton : public wxQtEventSignalHandler< QRadioButton, wxRadioButton >
{
public:
wxQtRadioButton( wxWindow *parent, wxRadioButton *handler ) :
wxQtEventSignalHandler< QRadioButton, wxRadioButton >(parent, handler)
{
connect(this, &QRadioButton::clicked, this, &wxQtRadioButton::OnClicked);
}
void OnClicked(bool checked)
{
wxRadioButton* handler = GetHandler();
if ( handler == NULL )
return;
wxCommandEvent event(wxEVT_RADIOBUTTON, handler->GetId());
event.SetInt(checked ? 1 : 0);
EmitEvent(event);
}
};
wxRadioButton::wxRadioButton() : wxRadioButton::wxRadioButton() :
m_qtRadioButton(NULL) m_qtRadioButton(NULL)
{ {
@@ -39,7 +62,7 @@ bool wxRadioButton::Create( wxWindow *parent,
const wxValidator& validator, const wxValidator& validator,
const wxString& name) const wxString& name)
{ {
m_qtRadioButton = new QRadioButton( parent->GetHandle() ); m_qtRadioButton = new wxQtRadioButton( parent, this );
m_qtRadioButton->setText( wxQtConvertString( label )); m_qtRadioButton->setText( wxQtConvertString( label ));
return QtCreateControl( parent, id, pos, size, style, validator, name ); return QtCreateControl( parent, id, pos, size, style, validator, name );