0

Hi am using wxWidgets and want to center the tabs in wxNotebook. The default position of the tab buttons are left(screenshot attached). That is they are aligned to the left of the window. How can I make the tab buttons to be at the center of the screen? In the screenshot two tab buttons/controls are shown which are aligned to the left. I have tried doing it by setting the style as wxBM_RIGHT in the wxNotebook constructor but that makes the tab go to the right side. There is no wxNB_CENTER, so how can I make the tabs stick to the middle of the screen? That is the tabs should be center/middle aligned. The sample code is as follows:

MyFrame::MyFrame(const wxString &title): wxFrame(NULL, wxID_ANY, title,wxDefaultPosition, wxSize(600,600))
{
wxPanel *mainPanel = new wxPanel(this, wxID_ANY);
wxNotebook *mainNotebook = new wxNotebook(mainPanel, wxID_ANY, wxDefaultPosition, wxSize(200,200),wxNB_RIGHT);/*i want tabs to be centered*/

wxPanel *tab1Panel = new wxPanel(mainNotebook, wxID_ANY);
wxPanel *tab2Panel = new wxPanel(mainNotebook, wxID_ANY);
mainNotebook->AddPage(tab1Panel, "Tab1", true, wxID_ANY);
mainNotebook->AddPage(tab2Panel, "Tab2", false, wxID_ANY);
}

My 2nd question is that is there a way to give the tabs some margins? Like the tabs should be some distance away from the top of the window.

Left aligned tabs

Jason
  • 36,170
  • 5
  • 26
  • 60

1 Answers1

0

@JasonLiam,

The answer to both questions is: You can't.

Centering tabs in wxNotebook is supported and is done by default on OSX only.

You can try to add a hidden tab, but I doubt it will help with the second problem.

HTH!

Igor
  • 5,620
  • 11
  • 51
  • 103
  • @jasonliam, they are not buttons - they are part of wxNotebook panels. So, no - you can't hide them. But you can switch them by clicking the button. Also try to build the `notebook` sample and see if there is another book control that will satisfy you need. – Igor Jun 19 '21 at 21:03
  • If you want a control with different pages where you switch pages based on button presses, there is [wxSimplebook](https://docs.wxwidgets.org/trunk/classwx_simplebook.html). You'll have to provide you're own code for switching pages in the button event handlers, but it shouldn't be too difficult. – New Pagodi Jun 20 '21 at 02:37