How do I send a wxEVT_COMMAND_SLIDER_UPDATED? 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
cr0nholio
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed Sep 12, 2007 8:54 am

How do I send a wxEVT_COMMAND_SLIDER_UPDATED?

Post by cr0nholio »

I need to generate a wxEVT_COMMAND_SLIDER_UPDATED event. It will not be enough to update the slider value using SetValue() but the user interaction of clicking the slider must be simulated. I read through the event handling docs but they are a bit confusing to me.

I assume I should generate a wxCommandEvent and then send it to the main window:

Code: Select all

wxCommandEvent *myEvent=new wxCommandEvent();
...
this->Command(myEvent);
But how do I set the event type and parameters? Can anyone point me in the right direction?
JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway »

Hi,

Not sure what you mean simulating user interaction, in any case you could create the event object as follows:

Code: Select all

wxCommandEvent evt = wxCommandEvent(wxEVT_COMMAND_SLIDER_UPDATED,window_id);
Where window_id is the id of the slider object.

Jim
OS: Vista SP1, wxWidgets 2.8.7.
cr0nholio
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed Sep 12, 2007 8:54 am

Post by cr0nholio »

Thanks, that helped, but it still doesn't work. Let's say I am trying to set the slider value to 50. I guessed that the SetInt() method of wxCommandEvent can be used for that. I tried:

Code: Select all

        wxCommandEvent evt=wxCommandEvent(wxEVT_COMMAND_SLIDER_UPDATED, ID_MYSLIDER);
        evt.SetInt(50);
        MySlider->Command(evt);
But nothing happened. Is it correct to run the Command() method of the slider or should it be the parent?
Not sure what you mean simulating user interaction
I mean simulating a mouse click on the slider so that not only the slider value will be changed but also the connected event handlers will be run.
JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway »

I get it what you're trying to do.

This should work:

Code: Select all

wxScrollEvent evt=wxScrollEvent(wxEVT_SCROLL_PAGEDOWN, ID_MYSLIDER);
evt.SetPosition(50);
evt.SetEventObject( MySlider );

MySlider->Command(evt);

Jim
OS: Vista SP1, wxWidgets 2.8.7.
cr0nholio
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed Sep 12, 2007 8:54 am

Post by cr0nholio »

Thanks, that makes sense. I tried the code and it does something but doesn't move the slider. :(
JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway »

That's odd, it works fine for me on Windows.

I presume your slider works properly if you operate it manually, and that you're trying to set a value that is it's allowable range.

What version, OS, etc. are you using?

Failing that, is there another code snippet you could share?

Jim
OS: Vista SP1, wxWidgets 2.8.7.
cr0nholio
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed Sep 12, 2007 8:54 am

Post by cr0nholio »

I presume your slider works properly if you operate it manually, and that you're trying to set a value that is it's allowable range.
Yes, it does. The range is 0-100, so 50 is valid.
What version, OS, etc. are you using?
wxWidgets 2.8, Ubuntu Feisty, g++ (GCC) 4.1.2
Failing that, is there another code snippet you could share?
I'm not free to share large chunks of code (the project is not open-source), but the reason I was asking is this:

I have 2 custom controls that each display a graph. When I initialize the frame and draw the 2 (different) graphs on the 2 controls, they will appear as the same graph, whichever I draw later. This seems to be either a bug in my code (though I couldn't find any problems) or a bug in wxWidgets itself. The funny thing is that it works well when I move the slider manually (the slider controls the offset of the graph): in this case the 2 graphs are different. I have been fighting for a while to fix this problem and now I thought I could work around it by simulating a click.
JimFairway
wxWorld Domination!
wxWorld Domination!
Posts: 1059
Joined: Sun Dec 30, 2007 6:40 pm
Location: Canada

Post by JimFairway »

Hi,

In the windows version, the wxSlider::Command has been overridden to look like this:

Code: Select all

void wxSlider::Command (wxCommandEvent & event)
{
    SetValue (event.GetInt());
    ProcessCommand (event);
}
The common code doesn't seem to do that.
Suggest you call SetValue yourself before you send the event off.

Jim
OS: Vista SP1, wxWidgets 2.8.7.
cr0nholio
Knows some wx things
Knows some wx things
Posts: 29
Joined: Wed Sep 12, 2007 8:54 am

Post by cr0nholio »

Thanks, it works now. It doesn't solve the bug though, but I will mark this as answered.

Thanks again for your assistance!
Post Reply