From: "Martin Cote" on
Hi,

This seems to be a recurrent problem on this mailing list, but I
didn't find any working solution so far.

I have a scrolled window with a vertical box sizer in it. I'm adding
panels in the sizer, so that they stack one above the other.
Everything works fine, except that the panels will never shrink below
their original width. They expand fine though. Here's a code sample
of the function that adds a panel in the scrolled window:

void ScrolledView::AddPanel( void )
{
Panel * panel = new wxPanel( this , wxID_ANY ) ;
sizer->Add( panel , 0 , wxEXPAND | wxALL , 2 ) ;
sizer->SetVirtualSizeHints( this ) ;
Refresh() ;
}

The added panel will expand to the width of the scrolled window when
AddPanel() is called, but this width seems to become its minimum width
also; it will never shrink below that size. I've tried many things,
like changing the minimum size of the panel after creation, but no
luck.

Also, I'm calling SetVirtualSizeHints to force the scrollbars to
update themselves after the new addition. Is this the right way to do
it?

Many thanks,
Martin Cote
_______________________________________________
wx-users mailing list
wx-users(a)lists.wxwidgets.org
http://lists.wxwidgets.org/cgi-bin/mailman/listinfo/wx-users

From: Vadim Zeitlin on
On Fri, 21 Mar 2008 13:42:46 -0400 Martin Cote <cote.martin(a)gmail.com> wrote:

MC> I have a scrolled window with a vertical box sizer in it. I'm adding
MC> panels in the sizer, so that they stack one above the other.
MC> Everything works fine, except that the panels will never shrink below
MC> their original width.

This is normal and not related to using scrolled window AFAICS. You can
use SetItemMinSize() explicitly if you can't decrease their original width.

MC> Also, I'm calling SetVirtualSizeHints to force the scrollbars to
MC> update themselves after the new addition. Is this the right way to do
MC> it?

If I'm not mistaken SetVirtualSizeHints() shouldn't be needed, calling
wxSizer::FitInside() should be enough.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

_______________________________________________
wx-users mailing list
wx-users(a)lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wx-users

From: "Martin Cote" on
Hi Vadim, thanks for the reply

On Sat, Mar 22, 2008 at 7:40 PM, Vadim Zeitlin <vadim(a)wxwidgets.org> wrote:
> On Fri, 21 Mar 2008 13:42:46 -0400 Martin Cote <cote.martin(a)gmail.com> wrote:
>
> MC> I have a scrolled window with a vertical box sizer in it. I'm adding
> MC> panels in the sizer, so that they stack one above the other.
> MC> Everything works fine, except that the panels will never shrink below
> MC> their original width.
>
> This is normal and not related to using scrolled window AFAICS. You can
> use SetItemMinSize() explicitly if you can't decrease their original width.

Indeed, this is not specific to the scrolled window. However, I had
no luck with SetItemMinSize, the child panels simply don't want to
shrink below their original widths. Is there anything else that I can
try?


> MC> Also, I'm calling SetVirtualSizeHints to force the scrollbars to
> MC> update themselves after the new addition. Is this the right way to do
> MC> it?
>
> If I'm not mistaken SetVirtualSizeHints() shouldn't be needed, calling
> wxSizer::FitInside() should be enough.

Hmmm, no luck with that either. Maybe all of my problems are wxMac
specific? I'm using Mac OS X 10.5. I'll try to post a short code
sample later with the hope that you will find something suspicious...

Thanks for your time,
Martin Cote
_______________________________________________
wx-users mailing list
wx-users(a)lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wx-users

From: "Martin Cote" on
On Sun, Mar 23, 2008 at 4:03 PM, Martin Cote <cote.martin(a)gmail.com> wrote:
> I'll try to post a short code sample later with the hope that you will find something suspicious...

Okay, I'm posting a fully working code sample here (sorry if it's
pretty long). Every time you press the a-key, it adds a new child in
the scrolled view. You'll notice that when you resize the window, the
child items grows correctly, but will never shrink below the original
size.

Here's the sample:

#include <wx/wx.h>

////////////////////////////////////////////////////////////////////////////////
class ScrollItem : public wxPanel
{
public:
ScrollItem( wxWindow * parent ) ;
} ;

ScrollItem::ScrollItem( wxWindow * parent )
: wxPanel ( parent , wxID_ANY )
{
wxSizer * sizer = new wxBoxSizer( wxHORIZONTAL ) ;

wxPanel * panel = new wxPanel( this , wxID_ANY ) ;
panel->SetBackgroundColour( *wxRED ) ;

wxCheckBox * check_box = new wxCheckBox( this , wxID_ANY , _T( "" ) ) ;

sizer->Add( panel , 1 , wxEXPAND | wxALL , 2 ) ;
sizer->Add( check_box , 0 , wxEXPAND | wxALL , 2 ) ;

SetSizer( sizer ) ;
}

////////////////////////////////////////////////////////////////////////////////
class ScrolledView : public wxScrolledWindow
{
public:
ScrolledView( wxWindow * parent ) ;
void Add( void ) ;
void OnChar( wxKeyEvent & event ) ;

DECLARE_EVENT_TABLE()

private:
wxSizer * sizer ;
} ;

BEGIN_EVENT_TABLE( ScrolledView , wxScrolledWindow )
EVT_CHAR( ScrolledView::OnChar )
END_EVENT_TABLE()

ScrolledView::ScrolledView( wxWindow * parent )
: wxScrolledWindow( parent , wxID_ANY )
{
SetScrollRate( 0 , 1 ) ;
sizer = new wxBoxSizer( wxVERTICAL ) ;
SetSizer( sizer ) ;
}

void ScrolledView::Add( void )
{
ScrollItem * item = new ScrollItem( this ) ;
sizer->Add( item , 0 , wxEXPAND | wxALL , 5 ) ;
sizer->SetVirtualSizeHints( this ) ;
Refresh() ;
}

void ScrolledView::OnChar( wxKeyEvent & event )
{
if( event.GetKeyCode() == 'a' )
Add() ;
}

////////////////////////////////////////////////////////////////////////////////
class Application: public wxApp
{
public:
bool OnInit( void ) ;
};

IMPLEMENT_APP( Application )

bool
Application::
OnInit( void )
{
wxFrame * frame = new wxFrame( 0 , wxID_ANY , _T( "" ) ) ;
wxSizer * sizer = new wxBoxSizer( wxVERTICAL ) ;

ScrolledView * scrolled_view = new ScrolledView( frame ) ;
sizer->Add( scrolled_view , 1 , wxEXPAND | wxALL , 5 ) ;
frame->SetSizer( sizer ) ;
frame->SetSize( wxSize( 300 , 500 ) ) ;
frame->Show( true ) ;
SetTopWindow( frame ) ;

return true ;
}

If you have any idea how I can solve this, that would be really appreciated.

Thanks a lot,
Martin Cote
_______________________________________________
wx-users mailing list
wx-users(a)lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wx-users

 | 
Pages: 1
Prev: Make error in wxwidgets
Next: wxBufferedDC drawing