Page 1 of 1

wxBoxSizer - background color

Posted: Sun Aug 26, 2018 9:00 am
by deepti
Hi All,

I have a wxDialog where many wxBoxSizer instances are added. Each wxBoxSizer contains a wxCollapsiblePane instance and a "Remove" button.
But, they have a grey background which is looking odd. Is there a way I can change this to the color of the wxPanel underneath, which is white?
Please see screenshot below:
Please help!
wxBoxSizer_color.jpg
wxBoxSizer_color.jpg (32.31 KiB) Viewed 714 times

Re: wxBoxSizer - background color

Posted: Sun Aug 26, 2018 2:57 pm
by PB
What OS is this? E.g. on MSW I believe the default panel colour is not white but light gray. The colour can be obtained by calling

Code: Select all

wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK)
Anyway, I do not know if this is the best solution, but you can change the background color of wxCollapsiblePane instances to any colour you want with SetBackgroundColour(). However, I noticed that this still keeps the original background color of the static box label. But you can change that with enumerating all children of the collapsible pane and set the background color indivdiually, e.g. calling the function below with an instance of a wxCollapsiblePane

Code: Select all

void SetBackgroundColourIncludingAllChildren(wxWindow* w, const wxColour& clr)
{
    w->SetBackgroundColour(clr);
    
    const wxWindowList& children = w->GetChildren();
    for ( wxWindowList::Node* node = children.GetFirst(); node; node = node->GetNext() )        
        SetBackgroundColourIncludingAllChildren(dynamic_cast<wxWindow*>(node->GetData()), clr);
}

Re: wxBoxSizer - background color

Posted: Mon Aug 27, 2018 7:38 am
by catalin
The OS must be Windows by the looks of the notebook. The "normal" panel color is indeed light grey, but a themed notebook page will have that white color, no matter the background color of the actual widget that was used. (And IIRC it will still report its original color even after adding it as a notebook page, which is a bit confusing.)
This could be a bug in wxCollapsiblePane, because a widgets should normally mimic transparency (have the same background as their parent).

wxStaticText used to suffer from the same problem and was fixed rather long time ago, which make me think that the wxW version is not recent. Otherwise you could try to create the wxCollapsiblePane instances after their wxPanel parent has been added to the notebook as a new page (so after the parent had gotten the new color).