Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

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
tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by tuk1 » Wed Apr 04, 2018 8:07 pm

This is the default background colour for frames on Microsoft Windows. You can get the familiar light-grey background by putting a wxPanel on the frame first, and putting all your other controls on this wxPanel. If the wxPanel is the only child window of the frame then it will automatically take up the entire client area of the frame.
https://wiki.wxwidgets.org/WxFAQ#Why_ar ... alog_boxes.
This does work, however putting the panel directly on an wxFrame means the wxFrame won't auto 'fit to content' due to the lack of sizer. Yes, the wxFrame size can be manually set with fixed xy, but auto 'fit to content' is the ideal.

Using a sizer gives an unwanted dark border via the underlap of wxFrame and the sizer:
Capture.PNG
Capture.PNG (5.11 KiB) Viewed 1647 times
-----

Is there an elegant solution to having both the correct background and wxFrame auto 'fit to content' ?
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2924
Joined: Sun Jan 03, 2010 5:45 pm

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by PB » Wed Apr 04, 2018 8:22 pm

You already have an answer to the title of the thread, so why ask this?

Obviously, you can set wxFrame's background to any color you wish with SetBackgroundColour() and you should be able to obtain the "panel" color with wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK).

The recommended way is to use wxPanel, not only because of its color but because it supposed to be well suited for having children controls, e.g. handling <Tab> navigation.

I do not understand the remark about autofitting the content, also there is no border around the sizer unless you add it there...

Code: Select all

#include <wx/wx.h>

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY, _("Test"))
    {        
        SetBackgroundColour(*wxRED);

        wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);

        wxPanel* panel = new wxPanel(this);
        panel->SetBackgroundColour(*wxBLUE);
        sizer->Add(panel, 1, wxEXPAND);
        
        SetSizer(sizer);
    }
};

class MyApp : public wxApp
{
public:
    virtual bool OnInit()
    {     
        (new MyFrame())->Show();               
        return true;
    }
}; wxIMPLEMENT_APP(MyApp);
frame.png
frame.png (1.83 KiB) Viewed 1640 times

User avatar
doublemax
Moderator
Moderator
Posts: 15832
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by doublemax » Wed Apr 04, 2018 8:58 pm

In addition to what PB wrote, a wxFrame never automatically sizes itself to fit its content, it always requires an explicit sizer call. You can call sizer->Fit( this ), even if the sizer is applied to the panel.
Use the source, Luke!

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by tuk1 » Thu Apr 05, 2018 1:04 pm

PB wrote:You already have an answer to the title of the thread, so why ask this?
Let me clarify the OP.
tuk1 wrote:This does work, however putting the panel directly on an wxFrame means the wxFrame won't auto 'fit to content' due to the lack of sizer. Yes, the wxFrame size can be manually set with fixed xy, but auto 'fit to content' is the ideal.
The first 3 words(in bold) in the OP acknowledge the faq answer, and a quote and link are also provided, the 4th word "however" indicates there might be a problem with the faq answer, the words that come after "however" answer your question, but be sure to let me know if the topic purpose is still unclear.

PB wrote: Obviously, you can set wxFrame's background to any color you wish with SetBackgroundColour() and you should be able to obtain the "panel" color with wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK).
Yes, you can do that, but it defeats the purpose of the solution given in the faq, which is what this topic is about.
Nor imo, does it meet the criteria of being an elegant solution.
PB wrote: I do not understand the remark about autofitting the content,
'Fit to content' is the term used by Julian Smart, hence the use of single quotes..

In code terms:

Code: Select all

if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
Without a sizer or setting fixed dims of the wxFrame ......the wxFrame will not expand to the correct size in relation to it's contents, aka ''Fit to content'.
PB wrote: ... also there is no border around the sizer unless you add it there...
Can you provide code that proves your statement?

Here is a picture of a bare bones project, containing a wxFrame, wxBoxSizerV and a wxPanel(dims 50,50), as you can see the dark grey border( underlap between the wxFrame and wxBoxSizerV) is there without being specifically added, unless I'm missing something?:
Capture.PNG
Capture.PNG (7.4 KiB) Viewed 1586 times

Code: Select all

testFrame::testFrame( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create( parent, id, caption, pos, size, style );
}

bool testFrame::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{

    wxFrame::Create( parent, id, caption, pos, size, style );

    CreateControls();
    if (GetSizer())
    {
        GetSizer()->SetSizeHints(this);
    }
    Centre();

    return true;
}
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

tuk1
Experienced Solver
Experienced Solver
Posts: 95
Joined: Sun Oct 08, 2017 9:36 am

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by tuk1 » Thu Apr 05, 2018 1:06 pm

doublemax wrote:In addition to what PB wrote, a wxFrame never automatically sizes itself to fit its content, it always requires an explicit sizer call. You can call sizer->Fit( this ), even if the sizer is applied to the panel.
I will play around with sizer->Fit( this ) to see if It eliminate the border as keeping the wxPanel seems advantageous.
wxWidgets(v3.1.3) - Vs2019(v142) - Win10(x64) - DialogBlocks(v5.16.5_Unicode)

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2924
Joined: Sun Jan 03, 2010 5:45 pm

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by PB » Thu Apr 05, 2018 1:24 pm

tuk1 wrote:
PB wrote:You already have an answer to the title of the thread, so why ask this?
Let me clarify the OP.
I answered the question you asked in the topic title, i.e., why is the color as it is. Once again, it is because wxWidgets try to be as native as possible and AFAIK the color is what is supposed to be there. That MS itself often ignores the guidelines is another thing, but you can still see the color being used in its older pure WIn32-based applications such as MSVS 2008...
tuk1 wrote:
PB wrote: ... also there is no border around the sizer unless you add it there...
Can you provide code that proves your statement?
You must have somehow missed the code and screenshot in my previous message, which clearly shows there is no border around the panel. It behaves the same on Windows 7:
framebkw7.png
framebkw7.png (14.04 KiB) Viewed 1583 times
Obviously, if you manually the set panel size smaller than the wxFrame client area, the border (gap) will be there because you asked for it. Moreover, it seems that the panel was created with a 3D border (wxBORDER_SUNKEN ?) as well, but as you did not provide the code to generate the screenshot I may be seeing things...

To conclude, you were provided were provided several simple working solutions to counter the default behavior. I am sorry that you found them lacking and hope you find a solution that will satisfy you.

User avatar
doublemax
Moderator
Moderator
Posts: 15832
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by doublemax » Thu Apr 05, 2018 2:50 pm

I will play around with sizer->Fit( this ) to see if It eliminate the border as keeping the wxPanel seems advantageous.
The border just comes from the border value when you add the wxpanel into a sizer like PB already explained. I was talking about the case, when you don't put the panel into a sizer. The sizer i was referring to is the on that's applied to the panel and that contains the rest of the controls.
Use the source, Luke!

delt
Earned a small fee
Earned a small fee
Posts: 24
Joined: Mon Dec 26, 2016 11:17 pm

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by delt » Mon Apr 22, 2019 8:15 pm

PB wrote:
Wed Apr 04, 2018 8:22 pm
Obviously, you can set wxFrame's background to any color you wish with SetBackgroundColour() and you should be able to obtain the "panel" color with wxSystemSettings::GetColour(wxSYS_COLOUR_FRAMEBK).
I found this is the best way to solve this problem. The docs state that the "ideal" way would be to put a wxPanel as only child of the frame, then put everything as child of that panel, but this has a problem with hidden widgets NOT being moved/resized properly, then appearing at the wrong place when i Show () them.

How come the "leading brand" is the ONLY (so-called) OS that is constantly causing headaches and hours of futzing around for the simplest little things??

User avatar
doublemax
Moderator
Moderator
Posts: 15832
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by doublemax » Mon Apr 22, 2019 8:19 pm

The docs state that the "ideal" way would be to put a wxPanel as only child of the frame, then put everything as child of that panel, but this has a problem with hidden widgets NOT being moved/resized properly, then appearing at the wrong place when i Show () them.
That *is* the best way. And it won't cause any layout issues unless you did something wrong.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4994
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Why are backgrounds of windows ugly, dark grey on Windows? I want them like my dialog boxes.

Post by ONEEYEMAN » Tue Apr 23, 2019 2:34 pm

Hi,
To the OP:
Why would anyone will NOT USE SIZERS?

Thank you.

Post Reply