How to get the initial size of a wxTextCtrl later after its creation? Topic is solved
How to get the initial size of a wxTextCtrl later after its creation?
Hello,
I need to get the initial size of a wxTextCtrl later after its size has been changed so I can resize it back to the initial size ?
TIA.
I need to get the initial size of a wxTextCtrl later after its size has been changed so I can resize it back to the initial size ?
TIA.
Re: How to get the initial size of a wxTextCtrl later after its creation?
Hi,.
Why?
Can't you call SetMinSize()/SetMaxSize()?
Thank you.
Why?
Can't you call SetMinSize()/SetMaxSize()?
Thank you.
Re: How to get the initial size of a wxTextCtrl later after its creation?
Hello,
sorry for the misunderstanding, what I meant is the default control size given by the system after creation using wxDefaultSize
Because, using wxDefaultSize outside the constructor or Create later has no meaning.
I wanted to know if there is a method I am not seeing that does this!
After some resizing, I just want to give back the default system size to the control.
TIA.
sorry for the misunderstanding, what I meant is the default control size given by the system after creation using wxDefaultSize
Because, using wxDefaultSize outside the constructor or Create later has no meaning.
I wanted to know if there is a method I am not seeing that does this!
After some resizing, I just want to give back the default system size to the control.
TIA.
Re: How to get the initial size of a wxTextCtrl later after its creation?
Hi,
But why?
What is so important with the wxTextCtrl that it has to remain the same size on resize?
Now, here is another trick question - do you want it to keep the same size when the parent window is moved to another monitor with different DPI?
Thank you.
But why?
What is so important with the wxTextCtrl that it has to remain the same size on resize?
Now, here is another trick question - do you want it to keep the same size when the parent window is moved to another monitor with different DPI?
Thank you.
Re: How to get the initial size of a wxTextCtrl later after its creation?
I guess that means you're not using sizers? Otherwise you'd never this question
Did you try just SetSize(wxDefaultSize) ?
Use the source, Luke!
Re: How to get the initial size of a wxTextCtrl later after its creation?
It has nothing to do with monitor or DPI.
The main reason to all of this is to provide it as a sample (I want to demonstrate something), when the user checks the checkbox it became huge, and when the user unchecks the checks box again its size has to go back to it normal size again (But I don't know what is the default size).
The main reason to all of this is to provide it as a sample (I want to demonstrate something), when the user checks the checkbox it became huge, and when the user unchecks the checks box again its size has to go back to it normal size again (But I don't know what is the default size).
Re: How to get the initial size of a wxTextCtrl later after its creation?
I thought, that unless specified otherwise, default size = best size = minimal size, i.e., obtainable by GetBestSize()?
However, I do not understand how you want to increase size of a wxCheckBox...
However, I do not understand how you want to increase size of a wxCheckBox...
Re: How to get the initial size of a wxTextCtrl later after its creation?
Before My application was crashing using SetSize(wxDefaultSize) and I thought it is not the correct way to use it.
But now, both SetSize(wxDefaultSize) and GetBestSize() worked for me.
This is really weird.
Re: How to get the initial size of a wxTextCtrl later after its creation?
I just tried it myself and SetSize(wxDefaultSize) did not work for me. Use GetBestSize().
If you're unsure if the window has a minimal size set, call SetMinSize( wxDefaultSize ) first.
If you're unsure if the window has a minimal size set, call SetMinSize( wxDefaultSize ) first.
Use the source, Luke!
Re: How to get the initial size of a wxTextCtrl later after its creation?
Yes, SetSize(wxDefaultSize) seemed working and tricked me again, and caused the application to crash.
Re: How to get the initial size of a wxTextCtrl later after its creation?
Even if it doesn't work as expected, it shouldn't crash. There must be something else going on.
Use the source, Luke!
Re: How to get the initial size of a wxTextCtrl later after its creation?
Hello,
Using wxWidgets v3.1.6 (dev)
This minimal patch (which I should have uploaded in the first place, sorry for wasting your time) explains what I was trying to achieve: But when I have tried it one more time, SetSize(wxDefaultSize); seems working.
Also, there is this problem that drove me nuts:
When I check the checkbox, the text control should resize to the desired size, that is (900, 300), but it is not. And if I comment out m_panel->Layout(); and recompile, it will this time, but when I uncheck the check box back the text control won't get to its default size. And only If I resize the main frame the text control will get back it original size (Because Layout() has been called implicitly).
what I'm missing here.
Thank in advance.
Using wxWidgets v3.1.6 (dev)
This minimal patch (which I should have uploaded in the first place, sorry for wasting your time) explains what I was trying to achieve: But when I have tried it one more time, SetSize(wxDefaultSize); seems working.
Also, there is this problem that drove me nuts:
When I check the checkbox, the text control should resize to the desired size, that is (900, 300), but it is not. And if I comment out m_panel->Layout(); and recompile, it will this time, but when I uncheck the check box back the text control won't get to its default size. And only If I resize the main frame the text control will get back it original size (Because Layout() has been called implicitly).
what I'm missing here.
Thank in advance.
Re: How to get the initial size of a wxTextCtrl later after its creation?
The code you posted works fine for me.
However, if you work with dynamic fontsizes, instead of using hard-coded sizes, why don't you leave it to the control?
How about this:
However, if you work with dynamic fontsizes, instead of using hard-coded sizes, why don't you leave it to the control?
How about this:
Code: Select all
void MyFrame::OnToggleBigSize(wxCommandEvent&)
{
wxFont font = m_txtCtrl->GetFont();
if( m_bigSizeCheck->GetValue() )
font.SetPointSize(font.GetPointSize() * 5);
else
font.SetPointSize(font.GetPointSize() / 5);
m_txtCtrl->InvalidateBestSize();
m_txtCtrl->SetFont(font);
m_panel->Layout();
}
Use the source, Luke!
Re: How to get the initial size of a wxTextCtrl later after its creation?
Thank you.
The solution to my problem is that I should replace every SetSize() by SetMinSize() because the sizer will always override the size set by SetSize().
And, as said in wxWindow::GetBestSize() documentation https://docs.wxwidgets.org/trunk/classw ... 9e319e35e3
BN: SetSize() documentation never mentioned that it is useless to call it in controls added to a containing Sizer and should use SetMinSize() instead.
The solution to my problem is that I should replace every SetSize() by SetMinSize() because the sizer will always override the size set by SetSize().
And, as said in wxWindow::GetBestSize() documentation https://docs.wxwidgets.org/trunk/classw ... 9e319e35e3
So in my case since I am using (gonna use) SetMinSize(), then GetBestSize() is avoidable.Notice that the best size respects the minimal and maximal size explicitly set for the window, if any. So even if some window believes that it needs 200 pixels horizontally, calling SetMaxSize() with a width of 100 would ensure that GetBestSize() returns the width of at most 100 pixels.
BN: SetSize() documentation never mentioned that it is useless to call it in controls added to a containing Sizer and should use SetMinSize() instead.