I have to dinamically fill a panel with wxStaticText and custom buttons (derived from wxWindow), one of each for each file i found in a directory.
They have to act and looks all the same with the exception of the "caption" text. "Building" them property by property when i new() them is tedious: i'd like more to have an original (designed in a IDE) and use it as a model.
There's a (safe, advisable) way to copy (or clone, or duplicate) an existing wxSomething? If yes, could it works also for event binding?
How to copy ("clone", "duplicate") wxControls?
Re: How to copy ("clone", "duplicate") wxControls?
Hi,
It sounds as if you're trying to reinvent the wheel . Just use a form-designer.
I use wxCrafter (and I'm pleased to say it has just been open-sourced) which is part of the CodeLite IDE; I'd expect other form-designers will do the same sort of thing though. In it, you'd create a wxStaticText, optionally setting its text. You can tell wxCrafter to duplicate it several times, then you change the text of each where needed. Similarly for other controls/sizers and their events.
You save that frame/panel/whatever as a 'base' class. Finally you derive your real class from that base class.
If you later want to change part of the design...no problem, just reopen wxCrafter, make the edits and export the base-class code again. Recompile and it's changed.
Regards,
David
It sounds as if you're trying to reinvent the wheel . Just use a form-designer.
I use wxCrafter (and I'm pleased to say it has just been open-sourced) which is part of the CodeLite IDE; I'd expect other form-designers will do the same sort of thing though. In it, you'd create a wxStaticText, optionally setting its text. You can tell wxCrafter to duplicate it several times, then you change the text of each where needed. Similarly for other controls/sizers and their events.
You save that frame/panel/whatever as a 'base' class. Finally you derive your real class from that base class.
If you later want to change part of the design...no problem, just reopen wxCrafter, make the edits and export the base-class code again. Recompile and it's changed.
Regards,
David
Re: How to copy ("clone", "duplicate") wxControls?
I'm using wxCrafter, and i don't see how your solution can expand dinamically (i mean: at runtime) depending on the content of a directory (just to use my case as example).DavidHart wrote: ↑Tue Mar 05, 2019 3:33 pm I use wxCrafter (and I'm pleased to say it has just been open-sourced) which is part of the CodeLite IDE; I'd expect other form-designers will do the same sort of thing though. In it, you'd create a wxStaticText, optionally setting its text. You can tell wxCrafter to duplicate it several times, then you change the text of each where needed. Similarly for other controls/sizers and their events.
Re: How to copy ("clone", "duplicate") wxControls?
My apologies: I didn't read your question carefully enough.
Alternatively you could use wxListCtrl or (better) one of the wxDataViewCtrl variants. See the relevant samples.
wxGenericDirCtrl displays the contents of a dir dynamically. However it doesn't use any sort of custom button.There's a (safe, advisable) way to copy (or clone, or duplicate) an existing wxSomething?
Alternatively you could use wxListCtrl or (better) one of the wxDataViewCtrl variants. See the relevant samples.
Re: How to copy ("clone", "duplicate") wxControls?
I have no problem in listing the files and create controls at runtime. I'd just like to avoid to set all properties one by one.DavidHart wrote: ↑Tue Mar 05, 2019 4:47 pm My apologies: I didn't read your question carefully enough.
wxGenericDirCtrl displays the contents of a dir dynamically. However it doesn't use any sort of custom button.There's a (safe, advisable) way to copy (or clone, or duplicate) an existing wxSomething?
Alternatively you could use wxListCtrl or (better) one of the wxDataViewCtrl variants. See the relevant samples.
That's why I would like to "ignore" the reason i mentioned as an example and stay on the question:
there's a way to "clone" an already existing control?
Re: How to copy ("clone", "duplicate") wxControls?
No.there's a way to "clone" an already existing control?
Use the source, Luke!