wxListCtrl Custom Draw
Amit
amitgupta.it at gmail.com
Thu Nov 30 03:18:47 PST 2006
Hi,
I want to customize the look of wxListCtrl. For this I capture
wxEVT_PAINT event and make a wxPaintDc object.
Using this object I do the desired drawing.
However this causes a side effect, i.e. wxListCtrl now fails to draw
it's own items. I guess this is happening because it's event handler is
not being called.
I also tried calling event.Skip(), both before and after my code but no
success.
then I tried calling wxListCtrl::OnPaint() function both before and
after my code. Now listctrl item's are drawn but my drawing is no more.
Is there a way using which I can draw over the default wxListCtrl
drawing.
OS : WinXP, wxWidgets 2.6.3
void ListCtrlPane::OnPaint(wxPaintEvent& event)
{
event.Skip();
wxRect itemRect;
wxPaintDC dc(this);
dc.SetPen(*wxRED_PEN);
int itemCount = GetItemCount();
long top = GetTopItem();
wxListItem ListItem;
ListItem.SetMask(wxLIST_MASK_TEXT);
int xBeg = 0, nWidth = 0;
for (int col = 0; col < GetColumnCount(); col++)
{
GetColumn(col, ListItem);
if(ListItem.GetText() == kStatus)
{
nWidth = GetColumnWidth(col);
break;
}
int colWidth = GetColumnWidth(col);
xBeg += colWidth ;
}
for (int i = top; i < top + GetCountPerPage() + 1; i++)
{
if (GetItemRect(i, itemRect))
{
itemRect.SetX(xBeg);
itemRect.SetWidth(nWidth);
dc.DrawRectangle(xBeg, itemRect.GetY(), nWidth,
itemRect.GetHeight());
}
}
wxListCtrl::OnPaint(event);
}
The idea is to draw a rectangle around a particular column.
Thanks in Advance
Regards
- Amit Gupta
More information about the wx-users
mailing list