wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
voyage
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Aug 31, 2018 1:58 pm

wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Post by voyage » Sat Aug 17, 2019 5:47 pm

I have made a dialog with a wxChoice and I have connected the wxEVT_COMMAND_CHOICE_SELECTED event to this function:

Code: Select all

void Prova_wxwidgetsDialog::OnChoice1Select(wxCommandEvent& event)
{
   wxBusyCursor wait;
   usleep(20000000);
}
I expect that for 20 seconds the mouse cursor change to BusyCursor but it doesn't.
What is wrong with this piece of code, how can I change the cursor with a BusyCursor after a choice selected event?
I have tried the code under ubuntu with wxwidgets 3.0.4

Kvaz1r
Earned some good credits
Earned some good credits
Posts: 133
Joined: Tue Jun 07, 2016 1:07 pm

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Post by Kvaz1r » Sat Aug 17, 2019 8:26 pm

It would be better if you provided reproducible example.

Does this code works for you?

Code: Select all

#include <wx/wx.h>

class MyFrame : public wxFrame
    {
    public:
        MyFrame(const wxString& title)   : wxFrame(NULL, wxID_ANY, title)
            {
			wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);

			wxString m_choiceChoices[] = { wxT("A"), wxT("B") };
			int m_choiceNChoices = sizeof(m_choiceChoices) / sizeof(wxString);
			m_choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_choiceNChoices, m_choiceChoices, 0);
			m_choice->SetSelection(0);
			m_choice->Bind(wxEVT_COMMAND_CHOICE_SELECTED,
				[](wxCommandEvent& ev)
				{
					wxBusyCursor wait;
					wxSleep(5);
				});
			topSizer->Add(m_choice, 0, wxALL, 5);

			this->SetSizer(topSizer);
			this->Layout();
            }
	protected:
		wxChoice* m_choice;
    };

class MyApp : public wxApp
    {
    public:
        virtual bool OnInit() 
            {
            if ( !wxApp::OnInit() )
                return false;
            MyFrame *frame = new MyFrame("wxWidgets application");
            frame->Show(true);
            return true;
            }
    };

wxIMPLEMENT_APP(MyApp);

voyage
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Aug 31, 2018 1:58 pm

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Post by voyage » Sun Aug 18, 2019 8:27 am

I have tried your code and it doesn't work as expected too. The cursor doesn't change while during the execution of the commands in the choice select event

User avatar
doublemax
Moderator
Moderator
Posts: 14194
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Post by doublemax » Sun Aug 18, 2019 8:49 am

Add a "::wxYield();" after setting the cursor.
Use the source, Luke!

voyage
In need of some credit
In need of some credit
Posts: 7
Joined: Fri Aug 31, 2018 1:58 pm

Re: wxChoice and event wxEVT_COMMAND_CHOICE_SELECTED

Post by voyage » Sun Aug 18, 2019 9:14 am

Thank you, with Yield now works. I don't understand why with Button click event it's not necessary Yield while it is with choice selected event?

Post Reply