wxScrolledWindow and Sizer

B. Carrupt capt at digicapt.ch
Wed May 9 07:42:42 PDT 2007


Hi,

I have a wxScrolledWindow into another wxScrolledWindow. When I set the scroll rate to use scroll bars in the inner wxScrolledWindow, my scrolled window is resized only when I make the frame bigger, not when I make it smaller.

Here is a complete sample that should compile. 

Note that it works perfectly on version 2.4 compiled with gtk under Fedora Core 2.

I use the version 2.8.3 on Fedora Core 6 and I compiled wx with gtk2.

Thanks for your help.

Blaise





#include <wx/wxprec.h>

#ifndef WX_PRECOMP
	#include <wx/wx.h>
#endif



class DcApp : public wxApp
{
public :
	virtual bool OnInit();
private :
  wxFrame	*mFrame;
};

DECLARE_APP(DcApp)
IMPLEMENT_APP(DcApp)

bool DcApp::OnInit()
{
  wxFlexGridSizer	*flexgridsizer;
  wxScrolledWindow	*pnlMain;
  wxStaticText		*lblTitle;
  wxScrolledWindow	*pnlData;
  wxStaticText		*lblData;
  wxTextCtrl		*edtData;
  wxScrolledWindow	*pnlButton;
  wxButton		*btnControl;
  

  mFrame = new wxFrame((wxFrame*) NULL,
		       -1,
		       "",
		       wxDefaultPosition, 
		       wxSize(500, 300));
  mFrame->SetSizer(new wxBoxSizer(wxVERTICAL));
  

  flexgridsizer = new wxFlexGridSizer(3, 1, 10, 10);
  flexgridsizer->AddGrowableCol(0, 0);
  flexgridsizer->AddGrowableRow(1, 0);
  pnlMain = new wxScrolledWindow(mFrame, 
				 wxID_ANY,
				 wxDefaultPosition,
				 wxSize(-1, -1),
				 wxHSCROLL | wxVSCROLL,
				 "pnlMain");
  pnlMain->SetSizer(flexgridsizer);
  mFrame->GetSizer()->Add(pnlMain, 1, wxEXPAND);

  lblTitle = new wxStaticText(pnlMain,
			      wxID_ANY,
			      "voici un titre qu'il est joli mais mal aligné",
			      wxDefaultPosition,
			      wxSize(400, 24),
			      0,
			      "lblTitle");
  pnlMain->GetSizer()->Add(lblTitle, 1, wxALIGN_RIGHT);  
  pnlMain->SetScrollRate(5, 5);

  flexgridsizer = new wxFlexGridSizer(4, 2, 1, 1);
  pnlData = new wxScrolledWindow(pnlMain,
				 wxID_ANY,
				 wxDefaultPosition,
				 wxSize(-1, -1),
				 wxHSCROLL | wxVSCROLL,
				 "pnlData");
  pnlData->SetSizer(flexgridsizer);
  pnlData->SetScrollRate(5, 5);	// IT SUCKS !!!
  pnlMain->GetSizer()->Add(pnlData, 1, wxEXPAND);

  lblData = new wxStaticText(pnlData,
			     wxID_ANY,
			     "premier",
			     wxDefaultPosition,
			     wxSize(-1, -1),
			     wxALIGN_LEFT,
			     "lblFirst");
  pnlData->GetSizer()->Add(lblData, 1, wxEXPAND);

  edtData = new wxTextCtrl(pnlData,
			   wxID_ANY,
			   "", 
			   wxDefaultPosition, 
			   wxSize(200, -1), 
			   0,
			   wxDefaultValidator, 
			   "edtFirst");
  pnlData->GetSizer()->Add(edtData, 1, wxEXPAND);

  lblData = new wxStaticText(pnlData,
			     wxID_ANY,
			     "deuxième",
			     wxDefaultPosition,
			     wxSize(-1, -1),
			     wxALIGN_LEFT,
			     "lblSecond");
  pnlData->GetSizer()->Add(lblData, 1, wxEXPAND);

  edtData = new wxTextCtrl(pnlData,
			   wxID_ANY,
			   "", 
			   wxDefaultPosition, 
			   wxSize(100, 10), 
			   0,
			   wxDefaultValidator, 
			   "edtSecond");
  pnlData->GetSizer()->Add(edtData, 1, wxEXPAND);
  
  flexgridsizer = new wxFlexGridSizer(1, 2, 20, 20);
  pnlButton = new wxScrolledWindow(pnlMain,
				   wxID_ANY,
				   wxDefaultPosition,
				   wxSize(-1, -1),
				   wxHSCROLL | wxVSCROLL,
				   "pnlButton");
  pnlButton->SetSizer(flexgridsizer);
  pnlMain->GetSizer()->Add(pnlButton, 1, wxEXPAND);

  btnControl = new wxButton(pnlButton,
			    wxID_ANY,
			    "Ok", 
			    wxDefaultPosition, 
			    wxSize(-1, -1), 
			    0,
			    wxDefaultValidator, 
			    "btnOk");
  pnlButton->GetSizer()->Add(btnControl, 1, wxEXPAND);

  btnControl = new wxButton(pnlButton,
			    wxID_ANY,
			    "Annuler", 
			    wxDefaultPosition, 
			    wxSize(-1, -1), 
			    0,
			    wxDefaultValidator, 
			    "btnCancel");
  pnlButton->GetSizer()->Add(btnControl, 1, wxEXPAND);
			
  mFrame->Show(TRUE);

  return true;
}






More information about the wx-users mailing list