Scrolling width SetTargetWindow Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Scrolling width SetTargetWindow

Post by kea_ » Wed Nov 18, 2009 2:50 pm

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.
Attachments
Windows.jpg
Just the right side should scrolling.
Windows.jpg (8.77 KiB) Viewed 1033 times

jfouche
Super wx Problem Solver
Super wx Problem Solver
Posts: 442
Joined: Tue May 06, 2008 4:52 pm
Location: France

Post by jfouche » Wed Nov 18, 2009 3:21 pm

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...
Jérémie

kea_
Experienced Solver
Experienced Solver
Posts: 59
Joined: Wed Oct 17, 2007 7:32 am

Post by kea_ » Thu Nov 19, 2009 6:19 am

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(){}

bertolino
Experienced Solver
Experienced Solver
Posts: 50
Joined: Wed Aug 14, 2013 8:07 am
Location: France
Contact:

Re: Scrolling width SetTargetWindow

Post by bertolino » Sun Dec 29, 2019 4:29 pm

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

Post Reply