wxBoxSizer - background color

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
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

wxBoxSizer - background color

Post 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 1789 times
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: wxBoxSizer - background color

Post 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);
}
catalin
Moderator
Moderator
Posts: 1618
Joined: Wed Nov 12, 2008 7:23 am
Location: Romania

Re: wxBoxSizer - background color

Post 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).
Post Reply