How to change the icon of IconTextColumn? Topic is solved

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
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

How to change the icon of IconTextColumn?

Post by apoorv569 »

I have one IconTextColumn in my wxDataViewListCtrl, I set a icon for it, now I want to change the icon to some other image upon clicking that column. I found this SetValue() which takes in a wxVariant &value, but it does nothing for me. Here is how I add the image,

Code: Select all

        wxVariant icon;
        icon << wxDataViewIconText(wxEmptyString, wxIcon("path_to_image"));

        if (tags.IsFileValid())
        {
            data.clear();
            data.push_back(icon);
            .
            .
            .
        }
And here I am trying to change the image of the column, for a specific row, the event is EVT_DATAVIEW_SELECTION_CHANGED

Code: Select all

            m_SampleListView->SetValue(wxVariant(wxDataViewIconText(wxEmptyString, wxIcon("path_to_image"))), selected_row, 0);
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: How to change the icon of IconTextColumn?

Post by doublemax@work »

The code looks ok to me. Try creating the wxDataViewIconText in a separate line and use its methods to check if it contains what you expect, especially if the icon is ok.
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to change the icon of IconTextColumn?

Post by apoorv569 »

doublemax@work wrote: Tue Jun 08, 2021 7:27 am The code looks ok to me. Try creating the wxDataViewIconText in a separate line and use its methods to check if it contains what you expect, especially if the icon is ok.
Thank you I found the problem, looks like my condition for when a icon should change was reversed, I was changing to same icon essentially. I switched the if else, now works.
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: How to change the icon of IconTextColumn?

Post by apoorv569 »

doublemax@work wrote: Tue Jun 08, 2021 7:27 am The code looks ok to me. Try creating the wxDataViewIconText in a separate line and use its methods to check if it contains what you expect, especially if the icon is ok.
BTW, is it possible to have some kind of slight animation/effect when the image changes?
User avatar
doublemax@work
Super wx Problem Solver
Super wx Problem Solver
Posts: 474
Joined: Wed Jul 29, 2020 6:06 pm
Location: NRW, Germany

Re: How to change the icon of IconTextColumn?

Post by doublemax@work »

apoorv569 wrote: Tue Jun 08, 2021 12:36 pm BTW, is it possible to have some kind of slight animation/effect when the image changes?
Not out of the box.
Post Reply