wxNotebook: Set size of window to fit all tabs

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
stefan__o
Knows some wx things
Knows some wx things
Posts: 32
Joined: Mon Aug 04, 2014 12:55 am

wxNotebook: Set size of window to fit all tabs

Post by stefan__o »

Hello,
I've got a window with a wxNotebook over the entire width with 5 tabs (fixed). The content of the tabs is adjusting to the window size. The size of the window is the minimal size using SetSizeHints. Unfortunately the window is set to the minimal size to fit the tab content, but not the tab header. I do not want tab scrolling, all 5 tab headers should fit in the window. I could not find any solution, any idea how to do that?
Best regards
Stefan
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxNotebook: Set size of window to fit all tabs

Post by doublemax »

If the wxNotebook is inside any kind of sizer, this should happen automatically. Can you show some code?
Use the source, Luke!
stefan__o
Knows some wx things
Knows some wx things
Posts: 32
Joined: Mon Aug 04, 2014 12:55 am

Re: wxNotebook: Set size of window to fit all tabs

Post by stefan__o »

This is the relevant code from the constructor (wxDialaog is the base class) I removed all the parts where widgets get added to the panels):

Code: Select all

	m_win_sizer = new wxGridSizer( 1,1,0,0 );

	wxNotebook *notebook = new wxNotebook(this,ID_Notebook,wxDefaultPosition,wxDefaultSize,wxNB_TOP);

	wxPanel *osmosdr_panel = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
	wxPanel *demod_panel = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
	wxPanel *csv_panel = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
	wxPanel *debug_panel = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );
	wxPanel *appearance_panel = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTAB_TRAVERSAL );

	wxGridBagSizer *top_sizer = new wxGridBagSizer(5,5);
	
	osmosdr_panel->SetSizerAndFit(osmosdr_sizer);
	demod_panel->SetSizerAndFit(demodulator_sizer);
	csv_panel->SetSizerAndFit(import_sizer);
	appearance_panel->SetSizerAndFit(design_sizer);
	debug_panel->SetSizerAndFit(debug_sizer);

	notebook->AddPage(osmosdr_panel,_T("OsmoSDR"));
	notebook->AddPage(demod_panel,_T("Demodulation"));
	notebook->AddPage(csv_panel,_T("CSV import"));
	notebook->AddPage(appearance_panel,_T("Appearance"));
	notebook->AddPage(debug_panel,_T("Debug"));

	top_sizer->Add(notebook,wxGBPosition(0,0),wxGBSpan(1,2),wxEXPAND | wxALL);
	top_sizer->Add(button_sizer,wxGBPosition(1,0),wxGBSpan(1,2), wxALL | wxALIGN_CENTER);
	top_sizer->AddGrowableCol(0,1);
	top_sizer->AddGrowableCol(1,1);
	top_sizer->AddGrowableRow(0,1);

	m_win_sizer->Add(top_sizer,0,wxEXPAND | wxALL,5);

	SetSizer(m_win_sizer);
	m_win_sizer->SetSizeHints(this);
The use of a wxGridBagSizer for the top window is caused by the widgets now arranged in tabs used to be all in the window
stefan__o
Knows some wx things
Knows some wx things
Posts: 32
Joined: Mon Aug 04, 2014 12:55 am

Re: wxNotebook: Set size of window to fit all tabs

Post by stefan__o »

I called notebook->GetBestFittingSize().GetWidth() to find out what is considered the best size:
Before adding pages: 6
After adding pages: 256
This is to fit the contents of the tabs, not the tab headers. I can use SetBestFittingSize to increase the width and it works, but how do I get the precise value to fit the tab headers?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxNotebook: Set size of window to fit all tabs

Post by doublemax »

As i can't test this easily, my guess is that the wxGrid* sizers are at fault. Can you make a test with just a wxBoxSizer and the notebook, nothing else?
Use the source, Luke!
stefan__o
Knows some wx things
Knows some wx things
Posts: 32
Joined: Mon Aug 04, 2014 12:55 am

Re: wxNotebook: Set size of window to fit all tabs

Post by stefan__o »

Sorry for the late answer. I removed the wxGridSizer, no difference. I tested on wxGTK and wxMSW, the same issue. Any idea?
I'll try to make an minimal example to show the problem.
Post Reply