wxScrolledWindow and Sizer
B. Carrupt
capt at digicapt.ch
Wed May 9 14:21:50 PDT 2007
When I stretch down the frame, the inner scrolled window become bigger and the buttons are pushed downwards, staying on the border of the frame. Exactly what I expect. But when I come back to the original size of the frame, the inner scrolled window keeps its size, the buttons disappear under the top of the frame and scrollbars appear.
In previous versions, the inner scrolled window became smaller and the buttons kept staying on the border of the frame.
Blaise
B. Carrupt wrote:
> 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.
The size of the outer wxScrolledWindow is determined by its biggest
child, in this case the wxStaticText lblTitle. Since the inner
wxScrolledWindow is equally streched to this size (400 pixels
wide) and its contents fits into these 400 pixel, no scroll
bars appear. There is nothing wrong.
Robert
>
> 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;
> }
--
B. Carrupt
More information about the wx-users
mailing list