How to use OnGetItemColumnImage Topic is solved
-
- Knows some wx things
- Posts: 29
- Joined: Mon Feb 10, 2020 3:09 am
How to use OnGetItemColumnImage
I am using a virtual wxListCtrl with a valid wxImageList set. I am inheriting from wxListCtrl and OnGetItemColumnImage is being called and I am returning the index of the image in the imagelist, but the image is never displayed. All the images are the same size (70 pixels). I also have OnGetItemText but I need images to be used in certain places and text to be used in other places. Also, if it is possible to not draw any image at certain times, that would be nice.
Last edited by TheGreatRambler on Mon Feb 10, 2020 8:56 pm, edited 1 time in total.
Re: How to use OnGetItemColumnImage
That sounds correct. Please post the relevant code parts (creating the wxListCtrl and wxImageList and the OnGetItemColumnImage handler).
Also: Which wxWidgets version and platform are you using?
Also: Which wxWidgets version and platform are you using?
Use the source, Luke!
-
- Knows some wx things
- Posts: 29
- Joined: Mon Feb 10, 2020 3:09 am
Re: How to use OnGetItemColumnImage
I was able to fix my problem, but I'm not sure exactly how I did it . I'll post the relevant examples for those that have problems with wxListCtrl and mixing text and images
As for the other stuff, make sure to use wxListCtrl::SetItemCount(int numberOfElements) whenever changing the number of elements. Everything should be automatic from there.
Code: Select all
DataProcessing::DataProcessing(wxWindow* parent) : wxListCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_VIRTUAL | wxLC_HRULES) {
// ...
// `imageList` is a member wxImageList of this custom class
int imageIconWidth = 50;
int imageIconHeight = 50;
imageList.Create(imageIconWidth, imageIconHeight);
// Do for each wxBitmap, remember the order the images were added
imageList.Add(*(new wxBitmap()));
// ... Repeat for each
InsertColumn(0, "Header for text", wxLIST_FORMAT_CENTER, wxLIST_AUTOSIZE);
// ... Repeat for each
InsertColumn(1, "Header with image", wxLIST_FORMAT_CENTER, wxLIST_AUTOSIZE);
// ...
SetImageList(&imageList, wxIMAGE_LIST_SMALL);
}
int DataProcessing::OnGetItemColumnImage(long row, long column) const {
if(column == 0) {
// This is intended to be text
return -1;
} else {
// Returns index in the imagelist
res = 0;
return res;
}
}
wxString DataProcessing::OnGetItemText(long row, long column) const {
if(column == 0) {
// Returns some sort of text
return "This is a row";
} else {
return "";
}
}