Page 1 of 1

Scrolling width SetTargetWindow

Posted: Wed Nov 18, 2009 2:50 pm
by kea_
Hello together,

I like to have a scrollbar over 2 windows and just scroll the right side one. See the picture below.

The scrollbars appears if I resize the wxScrolledWindow width the mouse.
But if I set the SetTargetWindow() the scrollbars will not appear anymore.

Code: Select all

coBasicView::coBasicView(wxWindow *wParent, wxWindowID iId, int iStyle)
           : wxScrolledWindow(wParent, iId, wxDefaultPosition, wxDefaultSize, iStyle){

    // Top sizer
    wxBoxSizer *szrTop = new wxBoxSizer(wxHORIZONTAL);
    SetSizer(szrTop);

    // Windows
    wxWindow *w1 = new wxWindow(this, ID_LEFT);
    wxWindow *w2 = new wxWindow(this, ID_BODY);

    szrTop->Add(w1, 0, wxALL | wxEXPAND, 0);
    szrTop->Add(w2, 1, wxALL | wxEXPAND, 0);

    w1->SetBackgroundColour("#ededed");
    w2->SetBackgroundColour("#e6e6e6");

    wxStaticText *stt1 = new wxStaticText(w1, 100, "my head", wxDefaultPosition, wxSize(120, 75));
    wxStaticText *stt2 = new wxStaticText(w2, 101, "my body", wxDefaultPosition, wxSize(100, 75));

    //SetTargetWindow(w2);
    SetScrollRate(2, 2);
}


coBasicView::~coBasicView(){}
I checked the sample but I'm to stuped.
Please give me a hint.

Posted: Wed Nov 18, 2009 3:21 pm
by jfouche
Well, I didn't try, but can you move your SetSizer(szrTop); at the end of the constructor and append Layout();

Code: Select all

coBasicView::coBasicView(wxWindow *wParent, wxWindowID iId, int iStyle)
           : wxScrolledWindow(wParent, iId, wxDefaultPosition, wxDefaultSize, iStyle){

    // Top sizer
    wxBoxSizer *szrTop = new wxBoxSizer(wxHORIZONTAL);

    // Windows
    wxWindow *w1 = new wxWindow(this, ID_LEFT);
    wxWindow *w2 = new wxWindow(this, ID_BODY);

    szrTop->Add(w1, 0, wxALL | wxEXPAND, 0);
    szrTop->Add(w2, 1, wxALL | wxEXPAND, 0);

    w1->SetBackgroundColour("#ededed");
    w2->SetBackgroundColour("#e6e6e6");

    wxStaticText *stt1 = new wxStaticText(w1, 100, "my head", wxDefaultPosition, wxSize(120, 75));
    wxStaticText *stt2 = new wxStaticText(w2, 101, "my body", wxDefaultPosition, wxSize(100, 75));

    //SetTargetWindow(w2);
    SetScrollRate(2, 2);

    SetSizer(szrTop);
    Layout();
}
Just to check...

Posted: Thu Nov 19, 2009 6:19 am
by kea_
Thank you for your answer.
No, this was not the solution.

But I found the solution.
Added just the SetScrollbars() at the end of the constructor.
And it work's.

But why do they take such a complicated example?

Anyway it works...
Great

Greeting kea_

Code: Select all

coBasicView::coBasicView(wxWindow *wParent, wxWindowID iId, int iStyle)
           : wxScrolledWindow(wParent, iId, wxDefaultPosition, wxDefaultSize, iStyle){

    // Top sizer
    wxBoxSizer *szrTop = new wxBoxSizer(wxHORIZONTAL);
    SetSizer(szrTop);

    // Windows
    wxWindow *w1 = new wxWindow(this, ID_LEFT);
    wxWindow *w2 = new wxWindow(this, ID_BODY);

    szrTop->Add(w1, 0, wxALL | wxEXPAND, 0);
    szrTop->Add(w2, 1, wxALL | wxEXPAND, 0);

    w1->SetBackgroundColour("#ededed");
    w2->SetBackgroundColour("#e6e6e6");

    wxStaticText *stt1 = new wxStaticText(w1, 100, "windows 1", wxDefaultPosition, wxSize(120, 75));
    wxStaticText *stt2 = new wxStaticText(w2, 101, "windows 2", wxDefaultPosition, wxSize(100, 75));

    SetTargetWindow(w2);
    SetScrollbars(2, 2, 40, 40);
    
}


coBasicView::~coBasicView(){}

Re: Scrolling width SetTargetWindow

Posted: Sun Dec 29, 2019 4:29 pm
by bertolino
Hello Kea_,

I just found your post (it's ten years old) that kindly brings THE solution to the issue I'm having for a couple of hours yet.
Many many thanks for sharing it!
Best regards,

Pascal