painting on wxListCtrl

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

painting on wxListCtrl

Post by Lloyd » Wed Aug 27, 2008 1:49 pm

Hi,
I am trying to paint on a ListCtrl, but nothing is drawn. The code snippet is given below. What could be the problem?

Code: Select all

void SearchHitList::OnPaint(wxPaintEvent& event)
{
 wxPaintDC dc(this); 
 dc.SetDeviceOrigin(0,0); 
  
 int cnt=GetCountPerPage();
 ++cnt;
 int top=GetTopItem();
 if(top>0)
  --top,++cnt;
 int w0=GetColumnWidth(0);
 int w1=GetColumnWidth(1);
 int w2=GetColumnWidth(2);
 wxRect rect;
 wxBrush br(wxColour(0,255,0),wxSOLID);
 wxPen pn(wxColour(0,255,0),wxSOLID);
 dc.SetBrush(br);
 dc.SetPen(pn);
 for(int i=0;i<cnt;++i)
 {
  if(GetItemRect(top+i,rect,wxLIST_RECT_BOUNDS))
  {
   dc.DrawRectangle(rect.x,rect.y,rect.width,rect.height);
  }
 }
}
The paint event is getting called. What could be the problem?

Thanks,
Lloyd

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Thu Aug 28, 2008 3:39 am

wxListCtrl's paint event handler is probably being called after yours, meaning whatever you're drawing is getting drawn on top of right after.

Maybe it would help to look at how CSSTint does it's custom painting on top of wxListCtrl to figure out how it can be done. I've avoiding doing this myself since controls like this were never meant to be drawn on top of like this, and with a cross-platform library like wxWidgets, you are very likely to run into problems getting it to work on every platform even if you get it working on one.

Lloyd
Super wx Problem Solver
Super wx Problem Solver
Posts: 350
Joined: Wed May 03, 2006 2:36 pm
Location: India
Contact:

Post by Lloyd » Thu Aug 28, 2008 12:27 pm

I just want to highlight a particular text in a list control in report mode, something like a search hit. Do you have another option for this?

Thanks,
Lloyd

User avatar
doublemax
Moderator
Moderator
Posts: 15183
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Thu Aug 28, 2008 1:28 pm

you could try wxDataViewCtrl, which gives you total freedom.

However, it's more complicated to use, it's only a generic contol on MSW (doesn't look very nice) and it doesn't seem to have been developed any further since its first appearance.

check /samples/dataview
Use the source, Luke!

Post Reply