Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6359619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:32:33+00:00 2026-05-24T23:32:33+00:00

I’m writing some wxWidgets samples for educational purposes. My problem is simple: I’m using

  • 0

I’m writing some wxWidgets samples for educational purposes.
My problem is simple: I’m using wxNotebook, and I need some trick to get current size of a single tab, especially height.
In simple terms, if I place a wxNotebook inside a wxFrame which have, for example, his wxMenubar – which, obviously, take up place in height -, I would get tab height value only, NOT wxFrame height value which also includes size of wxMenubar.
I need this information to properly center new components.

See the sample code below for an example.

#include "wx/wx.h"
#include "wx/gbsizer.h"

class MyFrame : public wxFrame
{   
    public:
        MyFrame() : wxFrame(NULL, wxID_ANY, wxT("Application"), wxDefaultPosition, wxSize(500, 300))
        {
            wxNotebook *tabs = new wxNotebook(this, wxID_ANY, wxPoint(-1,-1), wxSize(-1,-1), wxNB_TOP); 

            wxPanel *extPanel = new wxPanel(tabs, wxID_ANY); // external panel will be directly added to wxNotebook 

            wxPanel *innerPanel = new wxPanel(extPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize); /* for now, innerPanel has default size */

            innerPanel->SetBackgroundColour(wxColor(0, 0, 255)); // I change background color for debug only 

            innerPanel->SetMinSize(wxSize(200, 200)); // I use SetMinSize() method to communicate to the sizer _required_ size for the panel

            wxGridBagSizer *gbs = new wxGridBagSizer(3, 3); // I use a wxGridBagSizer to position one panel inside external

            /* **** THE FOLLOWING IS THE CRITICAL LINE **** */          

            wxSize mainSize = this->GetSize(); /* for now, I get the _wxFRAME_ wxSize; I would get wxNOTEBOOK size instead */


            wxSize innPSize = innerPanel->GetMinSize(); // I get current (Min)Size of innerPanel

            wxSize emptyCellSize((mainSize.GetWidth() - innPSize.GetWidth()) / 2, (mainSize.GetHeight() - innPSize.GetHeight()) / 2);       

            gbs->SetEmptyCellSize(emptyCellSize); // I Use SetEmptyCellSize() method to center the inner panel

            gbs->Add(innerPanel, wxGBPosition(1, 1)); // 1, 1: central cell 
            extPanel->SetSizer(gbs);

            tabs->AddPage(extPanel, wxT("Positioning test"));

            Show(true);
        }
};

class MyApp : public wxApp
{
    public:
        virtual bool OnInit()
        {
            MyFrame *frame = new MyFrame();
        }
};

IMPLEMENT_APP(MyApp);

As you can see, layout is imperfect.
p.s. If you know another, more efficient way to center a component using wxGridBagSizer, let me know.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:32:34+00:00Added an answer on May 24, 2026 at 11:32 pm

    Centering cells of a gridbag layouts can be done by labeling the columns or rows of the grid as “growable.” When a grid cell is labeled as growable, all of the cells will grow to take up all of the space given to it by the parent window (also the cells are automatically resized when the parent window is resized). For example, if you had 3 columns and wanted the middle column to be centered you can do this:

    wxGridBagSizer *gbs = new wxGridBagSizer(3, 3);
    gbs->AddGrowableCol(0, 1);
    gbs->AddGrowableCol(1, 2);
    gbs->AddGrowableCol(2, 1);
    gbs->AddGrowableRow(0, 1);
    gbs->Add(new wxPanel, wxGBPosition(0, 0), wxDefaultSpan, 0);
    gbs->Add(innerPanel, wxGBPosition(0, 1), wxDefaultSpan, wxEXPAND | wxCENTER);
    gbs->Add(new wxPanel, wxGBPosition(0, 2), wxDefaultSpan, 0);
    

    Here, 3 columns are created; for each column the AddGrowableCol() method has to be called to make the columns expand; the proportion variable tells the size how big each column should be in relation to all others. In this case, the middle column will be twice as big as the others. The AddGrowableRow method makes sure that the columns will take up the entire height of the parent panel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.