Custom slider control with text - how?
Volker Bartheld
dr_versaeg at freenet.de
Wed Feb 28 05:44:14 PST 2007
Hi!
>As a first step, I derived a class from
>wxControl, implemented Create() and defined a vertical sizer to which a
>wxSlider and a wxStatic text are added. Unfortunately, the static text
>is always displayed ontop of the slider instead of below (see code at
>the bottom of this post).
I ended up with deriving my "Control" from wxPanel:
<wxAdvancedSlider.cpp>
class wxAdvancedSlider : public wxPanel
{
DECLARE_DYNAMIC_CLASS(wxAdvancedSlider);
DECLARE_EVENT_TABLE();
public:
wxAdvancedSlider() : m_pSlider(NULL), m_pText(NULL) { }
wxAdvancedSlider(wxWindow* parent, wxWindowID id, int value , int minValue, int maxValue, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxSL_HORIZONTAL, const wxValidator& validator=wxDefaultValidator, const wxString& name=wxT("AdvancedSlider"))
{
Create(parent, id, value, minValue, maxValue, pos, size, style, validator, name);
}
bool Create(wxWindow* parent, wxWindowID id, int value , int minValue, int maxValue, const wxPoint& pos=wxDefaultPosition, const wxSize& size=wxDefaultSize, long style=wxSL_HORIZONTAL, const wxValidator& validator=wxDefaultValidator, const wxString& name=wxT("AdvancedSlider"))
{
if(!wxPanel::Create(parent, id, pos)) return false;
wxBoxSizer* pMainSizer=new wxBoxSizer(wxVERTICAL);
m_pSlider=new wxSlider(this, wxID_ANY, value, minValue, maxValue, pos, size, style, validator, name);
m_pText=new wxStaticText(this, wxID_ANY, name);
pMainSizer->Add(m_pSlider, 0, wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_TOP, 0);
pMainSizer->Add(m_pText, 0, wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 0);
SetSizer(pMainSizer);
SetInitialSize(size);
return true;
}
private:
wxSlider* m_pSlider;
wxStaticText* m_pText;
};
IMPLEMENT_DYNAMIC_CLASS(wxAdvancedSlider, wxPanel);
BEGIN_EVENT_TABLE(wxAdvancedSlider, wxPanel)
END_EVENT_TABLE()
</wxAdvancedSlider.cpp>
However, there might be unwanted side effects of that inheritage.
Cheers,
Volker
__
Mail replies to/an V B A R T H E L D at G M X dot D E
More information about the wx-users
mailing list