I have a simple custom control consisting of wxStaticText and wxTextCtrl in one sizer.
#include "wx/control.h"
class CParamCtrlEx : public wxControl
{
public:
CParamCtrlEx(void);
CParamCtrlEx(wxWindow *parent, wxWindowID id = wxID_ANY, float value_act = 0.0, float value_sp = 0.0, int dec_places = 1);
~CParamCtrlEx() {};
bool Create(wxWindow *parent, wxWindowID id);
private:
wxBoxSizer *sizer_ = nullptr;
wxStaticText *act_ = nullptr;
wxTextCtrl *sp_ = nullptr;
float value_act_ = 0.0;
float value_sp_ = 0.0;
int dec_places_ = 1;
private:
void UpdateDisplay();
CParamCtrlEx::CParamCtrlEx(void)
{
}
CParamCtrlEx::CParamCtrlEx(wxWindow *parent, wxWindowID id, float value_act, float value_sp, int dec_places) :
value_act_(value_act),
value_sp_(value_sp),
dec_places_(dec_places)
{
this->Create(parent, id);
}
bool CParamCtrlEx::Create(wxWindow *parent, wxWindowID id)
{
if (!this->wxControl::Create(parent, id, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE))
return false;
wxControl::InheritAttributes();
act_ = new wxStaticText(this, wxID_ANY, wxString::Format("%.*f /", dec_places_, value_act_));
sp_ = new wxTextCtrl(this, wxID_ANY, wxString::Format("%.*f", dec_places_, value_sp_), wxDefaultPosition, wxSize(50, -1), wxTE_RIGHT);
sizer_ = new wxBoxSizer(wxHORIZONTAL);
sizer_->Add(act_, wxSizerFlags(0).Align(wxALIGN_CENTER_VERTICAL).Border(wxRIGHT, 5));
sizer_->Add(sp_, wxSizerFlags(1).Expand().Border(wxLEFT | wxRIGHT, 0).FixedMinSize());
this->SetSizer(sizer_);
this->Layout();
return true;
}
void CParamCtrlEx::UpdateDisplay()
{
act_->SetLabel(wxString::Format("%.*f /", dec_places_, value_act_));
sp_->SetValue(wxString::Format("%.*f", dec_places_, value_sp_));
Refresh();
}
Everything would be fine, if it weren’t for the fact that my control has for some reason a different background colour than its parent wxPanel. It is somewhat darker.
I tried to use wxTRANSPARENT_WINDOW
style when calling this->wxControl::Create(...)
, but without success.
How do I fix the background colour?
New contributor
kamyllus is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.