wxDataViewListCtrl - IconTextColumn, how to centre align column data? 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.
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl - IconTextColumn, how to centre align column data?

Post by apoorv569 »

Using a custom column, with wxDataViewIconTextRenderer, still does not center align the icon,

Code: Select all

    wxDataViewColumn* c = new wxDataViewColumn("", new wxDataViewIconTextRenderer, 0, wxCOL_WIDTH_AUTOSIZE,
                                               wxALIGN_CENTRE, wxDATAVIEW_COL_RESIZABLE);

    // m_SampleListView->AppendIconTextColumn((wchar_t)U'🟊', wxDATAVIEW_CELL_ACTIVATABLE, 30, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE);
    m_SampleListView->AppendColumn(c);
    m_SampleListView->AppendTextColumn("Filename", wxDATAVIEW_CELL_INERT, 320, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
    m_SampleListView->AppendTextColumn("Sample Pack", wxDATAVIEW_CELL_INERT, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
Image
ONEEYEMAN wrote: Sat Jul 03, 2021 12:00 am Hi,
Yes, But you can override the renderer and use the icon instead.

Thank you.
I don't know how to override the renderer.
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxDataViewListCtrl - IconTextColumn, how to centre align column data?

Post by doublemax »

Do you need to display text in that column? If not, did you try AppendBitmapColumn()?
Use the source, Luke!
apoorv569
Super wx Problem Solver
Super wx Problem Solver
Posts: 426
Joined: Tue Oct 20, 2020 3:35 pm

Re: wxDataViewListCtrl - IconTextColumn, how to centre align column data?

Post by apoorv569 »

doublemax wrote: Sat Jul 03, 2021 12:59 am Do you need to display text in that column? If not, did you try AppendBitmapColumn()?
No I don't need text in this column only bitmap.
I tried AppendBitmapColumn(), but the bitmaps in the columns are not showing up,
Image

Here is the relevant code,

Code: Select all

    m_SampleListView->AppendBitmapColumn(wxBitmap(ICON_COLOURED), 0, wxDATAVIEW_CELL_ACTIVATABLE, 30, wxALIGN_CENTER, wxDATAVIEW_COL_RESIZABLE);
    m_SampleListView->AppendTextColumn("Filename", wxDATAVIEW_CELL_INERT, 320, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
    m_SampleListView->AppendTextColumn("Sample Pack", wxDATAVIEW_CELL_INERT, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
I did not understand what the 2nd argument is for, it says model_column, what is model_column.

Here is how I insert the image, with some help from this post - viewtopic.php?t=41192

Code: Select all

        wxVector<wxVariant> data;

        // wxVariant icon;
        // icon << wxDataViewIconText(wxEmptyString, wxIcon(ICON_GREYSCALE));

        if (tags.IsFileValid())
        {
            data.clear();
            data.push_back(wxVariant(wxBitmap(ICON_GREYSCALE)));          //  <-----------
            data.push_back(filename);
            data.push_back(sample.GetSamplePack());


EDIT:
I got it working, I had to change one of my function which loads the database back to application, it was still inserting,

Code: Select all

                    wxVariant icon_c, icon_gs;
                    // icon_c << wxDataViewIconText(wxEmptyString, wxIcon("../assets/icons/icon-hive_16x16.png"));
                    // icon_gs << wxDataViewIconText(wxEmptyString, wxIcon("../assets/icons/icon-hive_16x16-gs.png"));
I changed it to,

Code: Select all

                    wxVariant icon_c, icon_gs;
                    // icon_c << wxDataViewIconText(wxEmptyString, wxIcon("../assets/icons/icon-hive_16x16.png"));
                    // icon_gs << wxDataViewIconText(wxEmptyString, wxIcon("../assets/icons/icon-hive_16x16-gs.png"));

                    icon_c = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16.png"));
                    icon_gs = wxVariant(wxBitmap("../assets/icons/icon-hive_16x16-gs.png"));
Also had to change these, in multiple places, to toggle the image from coloured to greyscale, so it acts like a toggle column.

Code: Select all

                        m_SampleListView->SetValue(wxVariant(wxBitmap(ICON_GREYSCALE)), selected_row, 0);
Image

So I guess this is fixed.
Post Reply