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 8037431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:55:41+00:00 2026-06-05T02:55:41+00:00

When dynamically changing the size of the elements within a wxNotebook (e.g. hiding a

  • 0

When dynamically changing the size of the elements within a wxNotebook (e.g. hiding a button), the size of the whole notebook element is not updated. This can leave white space or prevent some elements from being shown.

Normally, a call to the parent window’s Fit() or FitInside() should do the trick, but doesn’t for the notebook. How can we resize it?

Minimal example demonstrating the problem:

#include <wx/wx.h>
#include <wx/gbsizer.h>
#include <wx/notebook.h>

const int HIDEME_ID = 512, SHOWME_ID = 513;

class MyApp: public wxApp
{
    wxButton* hideme;
    wxSizer* panel_sizer, *frame_sizer, *sw_sizer;
    wxScrolledWindow* sw;
    wxNotebook* nb;

    void hide_button( wxCommandEvent& ) {
        hideme->Hide();
        relayout();
    }
    void relayout() {
        /* Insert layout code here */
    }
    void show_button( wxCommandEvent& ) {
        hideme->Show();
        relayout();
    }
    virtual bool OnInit() {
        wxFrame *frame = new wxFrame( NULL, wxID_ANY, _("Hello World"), wxPoint(50, 50), wxSize(450, 340) );
        frame_sizer = new wxBoxSizer( wxVERTICAL );
        frame->SetSizer( frame_sizer );

        sw = new wxScrolledWindow( frame, wxID_ANY );
        sw->SetScrollRate( 5, 5 );
        frame_sizer->Add( sw, 1, wxEXPAND );

        sw_sizer = new wxBoxSizer( wxVERTICAL );
        sw->SetSizer( sw_sizer );

        nb = new wxNotebook( sw, wxID_ANY );
        wxPanel* panel = new wxPanel( nb, wxID_ANY );
        nb->AddPage( panel, wxT("Tab1") );

        sw_sizer->Add( new wxButton( sw, wxID_ANY, _("Button1"), wxDefaultPosition, wxSize(200,200) ), 0, wxEXPAND );
        sw_sizer->Add( nb, 0, wxEXPAND );
        sw_sizer->Add( new wxButton( sw, wxID_ANY, _("Button3") ), 1, wxEXPAND );
        sw_sizer->Add( new wxButton( sw, wxID_ANY, _("Button4") ), 0, wxEXPAND );

        panel_sizer = new wxBoxSizer( wxVERTICAL );
        panel_sizer->Add( hideme = new wxButton(panel, HIDEME_ID, wxT("HideMe")), 0, wxEXPAND );
        hideme->Hide();
        panel_sizer->Add( new wxButton(panel, SHOWME_ID, wxT("ShowMe")), 0, wxEXPAND );
        panel->SetSizer( panel_sizer );

        frame->Show(true);
        SetTopWindow(frame);
        return true;
    }

    DECLARE_EVENT_TABLE();
};

BEGIN_EVENT_TABLE(MyApp, wxApp)
    EVT_BUTTON(HIDEME_ID, MyApp::hide_button)
    EVT_BUTTON(SHOWME_ID, MyApp::show_button)
END_EVENT_TABLE()


IMPLEMENT_APP( MyApp );
  • 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-06-05T02:55:42+00:00Added an answer on June 5, 2026 at 2:55 am

    The somewhat surprising pitfall here is that, unlike many other windows, a wxNotebook caches its best size. We have to invalidate the cache before doing any layouting:

    nb->InvalidateBestSize();
    sw->FitInside();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've an img element with dynamically changing image. I always want to show this
I've already seen this post: Changing the size of Html.TextBox But I cannot change
How can you get access to the dynamically-changing coordinates of a draggable object? I
I am dynamically changing the cursor type on a Google Map using the Javascript
I have a jquery flexigrid that I'm dynamically changing so that it displays different
I have a JS function - triggered with onclick -, that is dynamically changing
I´m dynamically creating an instance of a class with reflection and this works fine,
I want to generate tooltip based on a dynamically changing background image in css.
I want to make my brightness and contrast shader change by dynamically changing offset
I use a QLabel to display the content of a bigger, dynamically changing QPixmap

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.