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
Custom Control
-
- CodeLite Veteran
- Posts: 59
- Joined: Wed Dec 31, 2014 6:36 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Custom Control
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
- 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
Make sure you have read the HOW TO POST thread
-
- CodeLite Veteran
- Posts: 59
- Joined: Wed Dec 31, 2014 6:36 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Custom Control
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
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
- eranif
- CodeLite Plugin
- Posts: 6375
- Joined: Wed Feb 06, 2008 9:29 pm
- Genuine User: Yes
- IDE Question: C++
- Contact:
Re: Custom Control
Thanks for reporting this, it should be fixed nownezos 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).
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)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?
I don't think you can do this with wxCrafter. You will need to handcraft this in your custom widgetnezos 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?
Eran
You do not have the required permissions to view the files attached to this post.
Make sure you have read the HOW TO POST thread