wxDialog not increasing in size to show all controls

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
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

wxDialog not increasing in size to show all controls

Post by deepti »

Hi All,

I have a wxDialog instance as created below:

But the problem is that none of the wxStaticText instances are shown!

The wxScrolledWindow is needed since many wxPanel of type "panelVersionInfo" need to be added dynamically.

Code: Select all

VersionsDialog::VersionsDialog(wxWindow* parent) : wxDialog(parent, -1, wxT("Previous Versions"),
	wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION | wxRESIZE_BORDER | wxSTAY_ON_TOP)
{
	m_panelVersionSettings = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
	boxSizerVersion = new wxBoxSizer(wxVERTICAL);
	m_panelVersionSettings->SetSizer(boxSizerVersion);

	m_VersionsScrolledWindow = new wxScrolledWindow(m_panelVersionSettings, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxBORDER_SIMPLE | wxVSCROLL);
	m_VersionsScrolledWindow->SetScrollRate(0, 16);

	m_VersionsControlsbox = new wxBoxSizer(wxVERTICAL);

	m_VersionsScrolledWindow->SetSizer(m_VersionsControlsbox);
	boxSizerVersion->Add(m_VersionsScrolledWindow, 1, wxALL | wxEXPAND, 5);

	wxPanel* panelVersionInfo = new wxPanel(m_VersionsScrolledWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);

	wxBoxSizer* fgs = new wxBoxSizer(wxHORIZONTAL);
	m_VersionsControlsbox->Add(fgs, 1, wxEXPAND, 0);

	fgs->Add(panelVersionInfo, 1, wxEXPAND, 0);

	wxStaticText* versionNum = new wxStaticText(panelVersionInfo, wxID_ANY, "versionName", wxDefaultPosition, wxDefaultSize);
	fgs->Add(versionNum, 1, wxALL | wxEXPAND, 5);

	wxStaticText* size = new wxStaticText(panelVersionInfo, wxID_ANY, "size", wxDefaultPosition, wxDefaultSize);
	fgs->Add(size, 1, wxALL | wxEXPAND, 5);

	wxStaticText* createdOn = new wxStaticText(panelVersionInfo, wxID_ANY, "createdon", wxDefaultPosition, wxDefaultSize);
	fgs->Add(createdOn, 1, wxALL | wxEXPAND, 5);


	
	m_VersionsControlsbox->SetSizeHints(m_VersionsScrolledWindow);
	m_VersionsScrolledWindow->FitInside();
	m_VersionsControlsbox->FitInside(m_VersionsScrolledWindow);
	m_VersionsScrolledWindow->Layout();
	m_VersionsControlsbox->Layout();
	SetSizerAndFit(m_VersionsControlsbox);
	//SetSizerAndFit(boxSizerVersion);
	this->Layout();
}
Please help!!
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDialog not increasing in size to show all controls

Post by doublemax »

It would be much easier to test this if you could provide compilable code, e.g. based on the "minimal" sample.
Use the source, Luke!
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog not increasing in size to show all controls

Post by deepti »

Hi @doublemax,

please find attached the files containing dialog class and the constructor definition.
Attachments
PropertiesDialog.h
(885 Bytes) Downloaded 86 times
PropertiesDialog.cpp
(2.2 KiB) Downloaded 70 times
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDialog not increasing in size to show all controls

Post by doublemax »

Based on your code i'm not quite sure how the end result is supposed to look like. Here's my version with everything stripped that seemed unnecessary (to me):

Code: Select all

VersionsDialog::VersionsDialog(wxWindow* parent) : wxDialog(parent, -1, wxT("Previous Versions"),
	wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION | wxRESIZE_BORDER | wxSTAY_ON_TOP)
{
	m_VersionsScrolledWindow = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(-1, -1), wxBORDER_SIMPLE | wxVSCROLL);
	m_VersionsScrolledWindow->SetScrollRate(0, 16);

	m_VersionsControlsbox = new wxBoxSizer(wxVERTICAL);

  for( int i=0; i<10; i++ )
  {
    wxPanel *panelVersionInfo = new wxPanel(m_VersionsScrolledWindow, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
    wxBoxSizer *fgs = new wxBoxSizer(wxHORIZONTAL);

    wxStaticText* versionNum = new wxStaticText(panelVersionInfo, wxID_ANY, "versionName", wxDefaultPosition, wxDefaultSize);
	  fgs->Add(versionNum, 1, wxALL | wxEXPAND, 5);

	  wxStaticText* size = new wxStaticText(panelVersionInfo, wxID_ANY, "size", wxDefaultPosition, wxDefaultSize);
	  fgs->Add(size, 1, wxALL | wxEXPAND, 5);

	  wxStaticText* createdOn = new wxStaticText(panelVersionInfo, wxID_ANY, "createdon", wxDefaultPosition, wxDefaultSize);
	  fgs->Add(createdOn, 1, wxALL | wxEXPAND, 5);

    panelVersionInfo->SetSizer( fgs );

    m_VersionsControlsbox->Add( panelVersionInfo, 0, wxALL, 4 );
  }

  m_VersionsScrolledWindow->SetSizer( m_VersionsControlsbox );

  // + 2/2 needed to make room for wxBORDER_SIMPLE
  // When using wxBORDER_NONE it would not be needed 
  SetClientSize( m_VersionsControlsbox->CalcMin() + wxSize(2,2) );
}
Hint: If you have a sizer that only contains one element, it's usually not needed at all.
Use the source, Luke!
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog not increasing in size to show all controls

Post by deepti »

Awesome @doublemax. That worked and the dialog controls are visible now.
Only issue is the gaps between the bitmap buttons on the right. How can i place them next to each other and not so apart?
Also, how can i achieve the dialog to be of a minimum size ? Setting the size of the dialog alone is not helping..
dialog.png
dialog.png (62.87 KiB) Viewed 2354 times
Please see the code below used to add the icons.
versionInfoButton is just a custom class derived from wxBitmapButton.

Code: Select all

versionInfoButton* downloadBut = new versionInfoButton(panelVersionInfo, dwnldButID, wxBitmap("./folder_open.png", wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(20, 20));
Connect(dwnldButID, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&VersionsDialog::OnDownloadVersion);
fgs->Add(downloadBut);

int delButID = ++ctrlID;
versionInfoButton* deleteBut = new versionInfoButton(panelVersionInfo, delButID, wxBitmap("./folder_open.png", wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(20,20));
Connect(delButID, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&VersionsDialog::OnDeleteVersion);
fgs->Add(deleteBut, wxALIGN_LEFT);

int makeLiveButID = ++ctrlID;
versionInfoButton* makeLiveBut = new versionInfoButton(panelVersionInfo, makeLiveButID, wxBitmap("./folder_open.png", wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(20, 20));
Connect(makeLiveButID, wxEVT_COMMAND_BUTTON_CLICKED, (wxObjectEventFunction)&VersionsDialog::OnMakeVersionLive);
fgs->Add(makeLiveBut, wxALIGN_LEFT);

User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDialog not increasing in size to show all controls

Post by doublemax »

Also, how can i achieve the dialog to be of a minimum size ? Setting the size of the dialog alone is not helping..
If you want all controls to be visible all the time, why did you use a scrolled window? Then you could have used a normal wxPanel instead.

Code: Select all

wxSize min_size =  m_VersionsControlsbox->CalcMin() + wxSize(2,2)
SetMinClientSize( min_size );
SetClientSize( min_size );
Usually you could use SetSizeHints / Fit for that, but they wouldn't include the (2,2) offset and the size would be a little bit too small and you'd get a scrollbar.
How can i place them next to each other and not so apart?
I thnk this is wrong:

Code: Select all

fgs->Add(deleteBut, wxALIGN_LEFT);
The second parameter to Add() is the propotion which should be 0. Try

Code: Select all

fgs->Add(deleteBut, 0, wxALIGN_LEFT);
instead
Use the source, Luke!
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog not increasing in size to show all controls

Post by deepti »

If you want all controls to be visible all the time, why did you use a scrolled window? Then you could have used a normal wxPanel instead.
The scrollbar is needed for vertical scrolling.
My intention is to have a fixed size dialog, say wxSize(1000, 500). And then when more controls are added, the scrollbar would take care of the vertical height growth.
How could i achieve this?

Also, the below code is not working too.. the bitmap buttons are still shown as before.
fgs->Add(deleteBut, 0, wxALIGN_LEFT);
Please help me with these 2 above issues.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDialog not increasing in size to show all controls

Post by doublemax »

My intention is to have a fixed size dialog, say wxSize(1000, 500). And then when more controls are added, the scrollbar would take care of the vertical height growth.
How could i achieve this?
The current code should already do this. Just set the window to wxSize(1000, 500) instead of the SetClientSize() call.
Also, the below code is not working too.. the bitmap buttons are still shown as before.
Can you show the complete sizer code you have right now?
Use the source, Luke!
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog not increasing in size to show all controls

Post by deepti »

The current code should already do this. Just set the window to wxSize(1000, 500) instead of the SetClientSize() call.
That worked..removing the SetClientSize() did the trick.
Can you show the complete sizer code you have right now?
Sure, please find attached the sample.cpp which has the entire code (minus our application specific code). Also attached the screenshot of the dialog.
dialog1.png
dialog1.png (53 KiB) Viewed 2319 times
The bitmap buttons have a lot of gap between them.

And another thing is w.r.t the heading. The heading and entries in the corresponding columns are misaligned, although i have provided the same amount of gap.Why could that be? :(
Attachments
sample.cpp
(5.41 KiB) Downloaded 75 times
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDialog not increasing in size to show all controls

Post by doublemax »

For a display like that, some kind of list control would be more suitable. E.g. a user might expect to be able to resize the column widths, which won't be possible right now. wxDataViewListCtrl would be better, but it will be more complicated to use and set up.

When using individual sizers like now, you will also have problems with aligning the items properly (as you've already seen).

In a wxGridSizer all "cells" have the same size, that's why the bitmap buttons are so far apart. Using a wxFlexGridSizer would solve this, but the problem with alignment would become even bigger.

The best solution would be to put all items into one sizer (instead of one sizer per row), but then you'd lose the option to color each line differently.

Unfortunately there is no easy solution that solves everything.
Use the source, Luke!
deepti
Earned some good credits
Earned some good credits
Posts: 115
Joined: Tue Jul 17, 2018 5:38 pm

Re: wxDialog not increasing in size to show all controls

Post by deepti »

@doublemax,

thank you for the letting me know that wxGridSizer makes all cells to be of the same size. That helped me fix almost all the issues - so now, i am using a wxFlexGridsizer and have specified the size of the controls. So, the UI looks pretty good :) thanks again!
Post Reply