Page 1 of 1

Custom Control

Posted: Sat Mar 07, 2015 2:20 am
by nezos
I've never written before a custom control using wxWidgets.

Can i use wxCrafter to create it?

->if yes is there a walkthrough available? or any hints would be useful
->if not do i first derive a wxControl class and code it's interface by hand and then enter it in the dialog of wxCrafter:Define a Custom Control?

Thanks

Re: Custom Control

Posted: Sat Mar 07, 2015 8:16 pm
by eranif
There are 2 types of custom controls
- A control that is a subclass of an existing control that adds new functionality (for example, a wxTextCtrl with auto complete list etc)
- A complete new generic control which is derived from wxPanel / wxControl

for the first case, its better to use the "Sublcass" property of the parent control. For example, if you developed some new type of wxTextCtrl, named "MyTextCtrl"
In wxCrafter, add "wxTextCtrl" as the control and in the "Subclass" field, set the name of the real class "MyTextCtrl". For this to work, the constructor of MyTextCtrl must match the constructor of wxTextCtrl

The second case: you want to develop a complete new control. So what you want here, is to create a new wxPanel top level and start connecting all the events you want ( for example, OnPaint, OnMouseDown etc )

Eran

Re: Custom Control

Posted: Mon Mar 16, 2015 1:50 pm
by nezos
I am trying now the second approach.

I created a new wxPanel, placed a static text and a wxchoice control. Went to Plugins->wxCrafter->Define Custom Control. Typed the class name i created for the wxPanel, type the .xrc file of the base class.

In the include file i had to type:

#include "C:\MyPath\MyClass.h"

(if i typed something else and then went to change it from Plugins->wxCrafter->Edit Custom Controls and hit Cancel it crashed. If i hit on the event tab, select add and then hit cancel it also crashed).

1) I see no preview in the design form nor it changes the size of it. Was i supposed to see by setting the xrc file?
2) If my panel has many controls, for example two Buttons, how can i connect the event, i mean i a saw the tooltip and it points to one event for the whole panel, how will i know which button was clicked? Do i need to define new custom events?

What i am trying to do is : I want to use 6 controls that will work together as one in many forms.
3) Would a better idea be to derive a class from wxSizer, put a blank sizer in the form and then dynamically assign the derived sizer?

Thanks in advance

Re: Custom Control

Posted: Mon Mar 16, 2015 3:34 pm
by eranif
nezos wrote:#include "C:\MyPath\MyClass.h"

(if i typed something else and then went to change it from Plugins->wxCrafter->Edit Custom Controls and hit Cancel it crashed. If i hit on the event tab, select add and then hit cancel it also crashed).
Thanks for reporting this, it should be fixed now
nezos wrote:1) I see no preview in the design form nor it changes the size of it. Was i supposed to see by setting the xrc file?
When using custom control, there is no preview (because there is no such stock control) the best you can do is to tell wxCrafter which widget to display instead (see attached image to see where to place it)
snapshot3.png
nezos wrote:2) If my panel has many controls, for example two Buttons, how can i connect the event, i mean i a saw the tooltip and it points to one event for the whole panel, how will i know which button was clicked? Do i need to define new custom events?
I don't think you can do this with wxCrafter. You will need to handcraft this in your custom widget

Eran