Hi all,
I'd like to detect a left mouse click on a wxSlider thumb (hence the slider value is not changed).
But there is no counterpart to wxEVT_SCROLL_THUMBRELEASE and mouse events are not available
for a wxSlider.
Any help will be welcome.
Regards,
Pascal
How to catch a left click on a wxSlider thumb
Re: How to catch a left click on a wxSlider thumb
Are you sure, have you tried? If these don't work, there probably is no way to do it.mouse events are not available for a wxSlider.
Use the source, Luke!
Re: How to catch a left click on a wxSlider thumb
They are. Because wxSlider inherit they from wxWindow.bertolino wrote: But there is no counterpart to wxEVT_SCROLL_THUMBRELEASE and mouse events are not available for a wxSlider.
About click events see this SO question - wxWidgets: Detecting click event on custom controls
Re: How to catch a left click on a wxSlider thumb
I have double-ckecked and still have the same issue. To be more precise:
I have several sliders, so I use the range macro (this could be the problem):
EVT_COMMAND_RANGE(ID_SLIDER, ID_SLIDER + MAX_PARAM_COUNT, wxEVT_LEFT_DOWN, Effects::OnSlider)
I've tried the 2 following OnSlider implementations:
(1) void Effects::OnSlider(wxCommandEvent& event)
The method is not called.
(2) void Effects::OnSliderClick(wxMouseEvent& event)
It doesn't compile, invalid type conversion.
Maybe, I should try not to use the macro to be able to cast and make the conversion work.
I'm also going to make the tests not with a range, just with one wxSlider.
Pascal
I have several sliders, so I use the range macro (this could be the problem):
EVT_COMMAND_RANGE(ID_SLIDER, ID_SLIDER + MAX_PARAM_COUNT, wxEVT_LEFT_DOWN, Effects::OnSlider)
I've tried the 2 following OnSlider implementations:
(1) void Effects::OnSlider(wxCommandEvent& event)
The method is not called.
(2) void Effects::OnSliderClick(wxMouseEvent& event)
It doesn't compile, invalid type conversion.
Maybe, I should try not to use the macro to be able to cast and make the conversion work.
I'm also going to make the tests not with a range, just with one wxSlider.
Pascal
Re: How to catch a left click on a wxSlider thumb
Code below works for me, try change it for your event:bertolino wrote: I've tried the 2 following OnSlider implementations:
Code: Select all
#include <wx/wx.h>
class MyFrame : public wxFrame
{
public:
MyFrame() : wxFrame(NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(600, 400))
{
wxBoxSizer* bSizer1 = new wxBoxSizer( wxVERTICAL );
m_logCtrl = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH2);
wxLog::SetActiveTarget(new wxLogTextCtrl(m_logCtrl));
m_slider = new wxSlider( this, wxID_ANY, 50, 0, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL );
bSizer1->Add(m_slider, 0, wxALL, 5 );
bSizer1->Add(m_logCtrl, 1, wxALL, 5 );
this->SetSizer( bSizer1 );
this->Layout();
this->Centre( wxBOTH );
m_slider->Bind(wxEVT_LEFT_UP,[](wxMouseEvent& event)
{
wxLogMessage("wxEVT_LEFT_UP");
event.Skip();
});
m_slider->Bind(wxEVT_SLIDER,[](wxCommandEvent& event)
{
wxLogMessage("wxEVT_SLIDER");
event.Skip();
});
}
protected:
wxSlider* m_slider;
wxTextCtrl* m_logCtrl;
};
class MyApp : public wxApp
{
public:
bool OnInit()
{
(new MyFrame)->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
Re: How to catch a left click on a wxSlider thumb
Hello Kvaz1r,
Many thanks for your valuable help and piece of code.
I'm going to replace the macro with a call to Bind.
Then I 'll just have to adapt the code to manage my slider range.
Many thanks again for your time,
Pascal
Many thanks for your valuable help and piece of code.
I'm going to replace the macro with a call to Bind.
Then I 'll just have to adapt the code to manage my slider range.
Many thanks again for your time,
Pascal
Re: How to catch a left click on a wxSlider thumb
Just to confirm that as Kvaz1r stated, the solution with Bind works well.
Of course, two methods are necessary to catch both
wxCommandEvent and wxMouseEvent.
Moral of the story: don't use event tables
Many thanks for the helps,
Pascal
Of course, two methods are necessary to catch both
wxCommandEvent and wxMouseEvent.
Moral of the story: don't use event tables
Many thanks for the helps,
Pascal
Re: How to catch a left click on a wxSlider thumb
Just for completeness sake: If you tried to catch mouse events for the slider using the event table for the frame, that only didn't work because unlike wxCommandEvents, wxMouseEvents don't propagate upwards in the window hierarchy. You can only catch them where they originate.Moral of the story: don't use event tables
Use the source, Luke!
Re: How to catch a left click on a wxSlider thumb
Thanks for the explanation doublemax.