Hello to everyone,
I have a problem :
I want to subclass wxPanel as my template for custom panel. In this derived wxPanel I can add normal controls as wxButton etc but I don't know how to add my custom draws (e.g. a border). In summary, I would mix normal wxControl and custom drawing in a wxPanel.
Can you help me?
Thanks
Stefano
subclass panel : custom draw and controls
Re: subclass panel : custom draw and controls
Basically, you need to catch the wxEVT_PAINT event and do your drawing in the event handler.
https://wiki.wxwidgets.org/Drawing_on_a_panel_with_a_DC
https://wiki.wxwidgets.org/Drawing_on_a_panel_with_a_DC
Use the source, Luke!
Re: subclass panel : custom draw and controls
thank you for your reply.
i will try to explain better.
For a single panel, how to draw in the render context it is ok.
The problem is fired when I try to detect EV_PAINT in a super class. I Have a set of panel, each of them extends a super class custompanel.
I would write a piece of generic code for all subclasses in only one place (the superclass) e.g. to draw a common border.
More in details I have ( only a portion of code ):
//SUPERCLASS
class CustomPanel : public wxPanel, public Observer {
public:
void OnPaint(wxPaintEvent& event);
DECLARE_EVENT_TABLE()
};
// Event table for CustomPanel
BEGIN_EVENT_TABLE(CustomPanel, wxPanel)
EVT_PAINT(CustomPanel::OnPaint)
END_EVENT_TABLE()
//SPECIALIZED AND CONCRETE CLASS
class SystemDateTimePanel : public CustomPanel
{
}
//END OF CODE
In this real example, hence the my problem, the evt_paint of superclass is never fired.
thank you
Stefano
i will try to explain better.
For a single panel, how to draw in the render context it is ok.
The problem is fired when I try to detect EV_PAINT in a super class. I Have a set of panel, each of them extends a super class custompanel.
I would write a piece of generic code for all subclasses in only one place (the superclass) e.g. to draw a common border.
More in details I have ( only a portion of code ):
//SUPERCLASS
class CustomPanel : public wxPanel, public Observer {
public:
void OnPaint(wxPaintEvent& event);
DECLARE_EVENT_TABLE()
};
// Event table for CustomPanel
BEGIN_EVENT_TABLE(CustomPanel, wxPanel)
EVT_PAINT(CustomPanel::OnPaint)
END_EVENT_TABLE()
//SPECIALIZED AND CONCRETE CLASS
class SystemDateTimePanel : public CustomPanel
{
}
//END OF CODE
In this real example, hence the my problem, the evt_paint of superclass is never fired.
thank you
Stefano
Re: subclass panel : custom draw and controls
Hi,
Are you catching EVT_PAINT in the derived class?
Thank you.
Are you catching EVT_PAINT in the derived class?
Thank you.
Re: subclass panel : custom draw and controls
Hi,
no I am not.
So I have to catch the event in the derived class, and then? Could I catch the event in the derived class and then call prior the superclass method (common to all derived class) ? I will try this.
thank you.
no I am not.
So I have to catch the event in the derived class, and then? Could I catch the event in the derived class and then call prior the superclass method (common to all derived class) ? I will try this.
thank you.
Re: subclass panel : custom draw and controls
I would suggest to catch the paint event only in the base class.
Then add a virtual method that does the actual painting. That can be overriden by the subclasses.
Then add a virtual method that does the actual painting. That can be overriden by the subclasses.
Code: Select all
void CustomPanel::OnPaint( wxPaintEvent &evt )
{
wxPaintDC dc(this);
DoDraw( dc );
}
virtual void CustomPanel::DoDraw( wxDC &dc )
{
// do actual drawing here.
}
Use the source, Luke!
Re: subclass panel : custom draw and controls
Hi,
Also, make sure you call Refresh()/Update() to send the paint event.
Thank you.
Also, make sure you call Refresh()/Update() to send the paint event.
Thank you.