wxTextCtrl password entry with show&hide password option
wxTextCtrl password entry with show&hide password option
Is there any shortcut or should we create two wxTextCtrls, one with wxTE_PASSWORD, one without and switch between them when the show/hide password toggle is activated?
Documentation says wxTE_PASSWORD style can only be dynamically changed with wxGTK back-end.
Documentation says wxTE_PASSWORD style can only be dynamically changed with wxGTK back-end.
Re: wxTextCtrl password entry with show&hide password option
I can't think of an easier way.
The alternative would be to catch all key presses, store the characters only internally and then replace it with an * for the actual visible content. But it would become quite complicated with handling cursor movement, selection, backspace, delete etc.
The alternative would be to catch all key presses, store the characters only internally and then replace it with an * for the actual visible content. But it would become quite complicated with handling cursor movement, selection, backspace, delete etc.
Use the source, Luke!
Re: wxTextCtrl password entry with show&hide password option
I see. I will try abstracting this thing away.
Re: wxTextCtrl password entry with show&hide password option
It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Re: wxTextCtrl password entry with show&hide password option
Hi
Regards
If you need an example, just have a look at this : this is exactly what I am doing.catalin wrote:It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.
Regards
My wxWidgets stuff web page : X@v's wxStuff
Re: wxTextCtrl password entry with show&hide password option
Under which license can we look at your work?xaviou wrote:....this ...
Re: wxTextCtrl password entry with show&hide password option
I don't know how to ensure that they'd have the same position in the sizer. But I could put two of them in and Show()/Hide() them when needed.catalin wrote:It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.
- xaviou
- Super wx Problem Solver
- Posts: 437
- Joined: Mon Aug 21, 2006 3:18 pm
- Location: Annecy - France
- Contact:
Re: wxTextCtrl password entry with show&hide password option
There is no particular license : you can do what you want with it.specing wrote:Under which license can we look at your work?
It's here to help...
It can also work : just don't forget to call "layout" on the containing sizer after the "show/hide" onesspecing wrote:I don't know how to ensure that they'd have the same position in the sizer. But I could put two of them in and Show()/Hide() them when needed.catalin wrote:It may be easier to recreate a text ctrl at every toggle event, having the same size, position, value, parent [, position in sizer], and maybe also use Freeze()/Thaw() on its parent when switching the 2 controls.
Regards
Xav'
My wxWidgets stuff web page : X@v's wxStuff
Re: wxTextCtrl password entry with show&hide password option
I'm pretty sure "no license" means all rights reserved under current copyright systems. If you want to dedicate those samples to the public domain, then explicitly pick such a license, e.g. Creative Commons Zero and follow their licensing practice (e.g. /LICENSE file and proper text in all headers). I'm also sure that using some person's "you can do what you want with it." quote on some forum where anyone can register with whatever name and claim they are the author of that software will not fly in a courtroom.xaviou wrote:There is no particular license : you can do what you want with it.
Re: wxTextCtrl password entry with show&hide password option
FWIW, I find that Xaviou's solution may work only if the password text control is the only or last control in a sizer, and even with moving it to the last box, I had no luck with in wxGridSizer.
The problem seems to be that, while a sizer has functions to add a control at a given index, I have not found a way to check at which index the current control was placed to that I could try to 'insert' it at the desired 'index', rather than append it with pSzr->add which says it will append the recreated text control
As it is adding the control seems to place it at some arbitrary point within the grid sizer - at least I can see no logic, because it does not even become the last control in the sizer
Even getting both size & position of the old window and using it when creating the new one does not make a difference.
It does seem that, for Windows at least, there is an alternative - will check it out.
viewtopic.php?t=15093
The problem seems to be that, while a sizer has functions to add a control at a given index, I have not found a way to check at which index the current control was placed to that I could try to 'insert' it at the desired 'index', rather than append it with pSzr->add which says it will append the recreated text control
As it is adding the control seems to place it at some arbitrary point within the grid sizer - at least I can see no logic, because it does not even become the last control in the sizer
Even getting both size & position of the old window and using it when creating the new one does not make a difference.
It does seem that, for Windows at least, there is an alternative - will check it out.
viewtopic.php?t=15093
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2
Re: wxTextCtrl password entry with show&hide password option
FWIW you should be able to achieve this without needing the index, by storing the wxSizerItem* returned by wxSizer::Add(...) and using its AssignWindow() when appropriate.
Re: wxTextCtrl password entry with show&hide password option
the 'solution' may well be 'obvious' to you, but it is not to me and the example may well work under some (unspecified) conditions, but not under mine
Environment: Win 10/11 64-bit & Mint 21.1
MSVC Express 2019/2022
wxWidgets 3.2.2
MSVC Express 2019/2022
wxWidgets 3.2.2