Problem with Sizers Topic is solved

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
Tony0945
Earned some good credits
Earned some good credits
Posts: 105
Joined: Wed Oct 21, 2009 4:02 pm

Problem with Sizers

Post by Tony0945 »

My app is based on wxFrame and has a Toolbar and two panels (different colors) arranged in a "T" with the Toolbar sitting above the two panels. I don't want any space between the widgets, but I am getting some kind of border because the frame background shows through between the toolbar and panels and also below the panels. What am I doing wrong?

The sizers are created and filled as follows:

Code: Select all

void MoneycloneFrm::CreateGUIControls()
{
// various widget creation stuff
// ...

// Now create the sizers
	VerticalSizer = new wxBoxSizer(wxVERTICAL);

	
	VerticalSizer->Add(NavigationBar,0,0,0);
	HorizontalSizer = new wxBoxSizer(wxHORIZONTAL);

	HorizontalSizer->Add(BackgroundPanel,0,wxEXPAND,0);
	HorizontalSizer->Add(AccountPanel,5,wxEXPAND,0);
	
	VerticalSizer->Add(HorizontalSizer, 100, wxEXPAND,0);
	VerticalSizer->Layout();
	HorizontalSizer->Layout();
	
	this->SetSizer(VerticalSizer);
	this->SetAutoLayout(true);	
}
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

I tried this code on wxOSX 2.9.1 and did not get any space between the panels

Code: Select all

#include "wx/wx.h"

class MyFrame : public wxFrame
{
public:
    MyFrame() : wxFrame(NULL, wxID_ANY,  wxT("Hello wxWidgets"), wxPoint(50,50), wxSize(800,600))
    {
        wxBoxSizer* VerticalSizer = new wxBoxSizer(wxVERTICAL);
        
        wxPanel* NavigationBar = new wxPanel(this);
        NavigationBar->SetMinSize( wxSize(50, 50) );
        NavigationBar->SetBackgroundColour(*wxBLUE);
        VerticalSizer->Add(NavigationBar,0,0,0);
        wxBoxSizer* HorizontalSizer = new wxBoxSizer(wxHORIZONTAL);
        
        wxPanel* BackgroundPanel = new wxPanel(this);
        BackgroundPanel->SetBackgroundColour(*wxRED);
        BackgroundPanel->SetMinSize( wxSize(50, 50) );
        wxPanel* AccountPanel = new wxPanel(this);
        AccountPanel->SetBackgroundColour(*wxGREEN);
        AccountPanel->SetMinSize( wxSize(50, 50) );

        HorizontalSizer->Add(BackgroundPanel,0,wxEXPAND,0);
        HorizontalSizer->Add(AccountPanel,5,wxEXPAND,0);
        
        VerticalSizer->Add(HorizontalSizer, 100, wxEXPAND,0);
        VerticalSizer->Layout();
        HorizontalSizer->Layout();
        
        this->SetSizer(VerticalSizer);
        this->SetAutoLayout(true); 
    }
};

class MyApp: public wxApp
{
    wxFrame* m_frame;
public:
    
    bool OnInit()
    {
        m_frame = new MyFrame();
        m_frame->Show();
        return true;
    } 
    
};

IMPLEMENT_APP(MyApp)
can you say which platform and post a screenshot?
"Keyboard not detected. Press F1 to continue"
-- Windows
Tony0945
Earned some good credits
Earned some good credits
Posts: 105
Joined: Wed Oct 21, 2009 4:02 pm

Post by Tony0945 »

The calls to SetMinSize() did the trick. The Platform is Windows 2000.

I put some debug code in to display the minimum sizes.
The original min size for the bar was 18h 543w. The original size of the left panel was -1,-1. The original size of the right panel was also -1,-1. The actual sizes were set much larger in the constructor. Apparently the minimum size for a toolbar is the original size, but the minimum size of a panel is not.
Post Reply