Problems with wxScrolledWindow

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
JohnD
Earned some good credits
Earned some good credits
Posts: 118
Joined: Fri Nov 21, 2008 2:18 pm

Problems with wxScrolledWindow

Post by JohnD » Mon Dec 12, 2011 4:32 pm

I imagine this must be a common issue, but when my wxScrolledWindow contains enough elements to display the vertical slider, the reduced width due to the vertical slider being shown is causing the horizontal slider to also appear.

I'm not setting any sizes explicitly, the wxScrolledWindow is a child of a wxPanel.

As a quick hack I thought I could turn off the horizontal scrollbar:

Code: Select all

new wxScrolledWindow(this,-1,wxDefaultPosition,wxDefaultSize,wxVSCROLL);
But this makes no difference.

Here is my code - SettingsPanel is a subclass of wxPanel:

Code: Select all

		SettingsPanel::SettingsPanel( wxWindow* parent ) : wxPanel(parent)
		{
			wxBoxSizer *settingsSizer = new wxBoxSizer(wxVERTICAL);

			settingsScrollWindow = new wxScrolledWindow(this,-1,wxDefaultPosition,wxDefaultSize,wxVSCROLL);
			settingsScrollWindow->SetScrollRate( 10, 10 );
			settingsScrollSizer = new wxBoxSizer(wxVERTICAL);
			settingsScrollWindow->SetSizer(settingsScrollSizer);
			.
			. //add controls to the scroll window here
			.
			settingsSizer->Add(settingsScrollWindow,1,wxEXPAND);	
			SetSizer(settingsSizer);
		}
Is there some obvious step I am missing, or a simple call I can make?

I just either want the H-scrollbar to be disabled, or to leave space for the V-scrollbar in the width. I would settle for the V-scroll being always visible or something - after an easy quick fix only here that avoids a dumb H-scroll that scrolls about 10px :)

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Problems with wxScrolledWindow

Post by Auria » Mon Dec 12, 2011 5:37 pm

Hi,

which OS and wx version? the following code works for me under wxOSX/Cocoa 2.9.3

Code: Select all

#include "wx/wx.h"
#include <iostream>

class ScrolledWidgetsPane : public wxScrolledWindow
{
public:
    ScrolledWidgetsPane(wxWindow* parent, wxWindowID id) : wxScrolledWindow(parent, id)
    {
        // the sizer will take care of determining the needed scroll size
        // (if you don't use sizers you will need to manually set the viewport size)
        wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
        
        // add a series of widgets
        for (int w=1; w<=120; w++)
        {
            wxButton* b = new wxButton(this, wxID_ANY, wxString::Format(wxT("Button %i"), w));
            sizer->Add(b, 0, wxALL | wxEXPAND, 3);
        }
        
        this->SetSizer(sizer);
        
        // this part makes the scrollbars show up
        this->FitInside(); // ask the sizer about the needed size
        this->SetScrollRate(5, 5);
    }
    
};

// A sample app that adds the scrolled pane to a frame to make this code runnable
class MyApp: public wxApp
{
    wxFrame *frame;
public:
    
    bool OnInit()
    {
        wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
        frame = new wxFrame((wxFrame *)NULL, -1,  wxT("Scrolling Widgets"), wxPoint(50,50), wxSize(650,650));
        
        ScrolledWidgetsPane* my_image = new ScrolledWidgetsPane(frame, wxID_ANY);
        sizer->Add(my_image, 1, wxEXPAND);
        frame->SetSizer(sizer);
        
        frame->Show();
        return true;
    } 
};

IMPLEMENT_APP(MyApp)
"Keyboard not detected. Press F1 to continue"
-- Windows

JohnD
Earned some good credits
Earned some good credits
Posts: 118
Joined: Fri Nov 21, 2008 2:18 pm

Re: Problems with wxScrolledWindow

Post by JohnD » Mon Dec 12, 2011 7:44 pm

Win7, wx2.8.10.

wx's sizing still confuses me but I think the issue could be that the parent wxPanel is getting resized after all the children are added to the wxScrolledWindow... but I could be wrong. Should I be calling wxScrolledWindow::FitInside every time the parent window is sized, or should it be automatic?

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Problems with wxScrolledWindow

Post by Auria » Mon Dec 12, 2011 11:05 pm

Could you try my sample and see if it works for you? If we can eliminate that some other code might be at cause it will help
"Keyboard not detected. Press F1 to continue"
-- Windows

JohnD
Earned some good credits
Earned some good credits
Posts: 118
Joined: Fri Nov 21, 2008 2:18 pm

Re: Problems with wxScrolledWindow

Post by JohnD » Tue Dec 13, 2011 9:02 am

Did you want me to try your whole app sample to test on my Win/wx version, or for me to try and use your scrollable class in my existng code?

Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: Problems with wxScrolledWindow

Post by Auria » Tue Dec 13, 2011 4:48 pm

JohnD wrote:Did you want me to try your whole app sample to test on my Win/wx version, or for me to try and use your scrollable class in my existng code?
trying this sample alone would be better as a first step, since then we're sure there is no interference from other code
"Keyboard not detected. Press F1 to continue"
-- Windows

Post Reply