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

wxDataViewListCtrl - IconTextColumn, how to centre align column data?

Post by apoorv569 »

I have a IconTextColumn in wxDataViewListCtrl, in which I show a greyscale icon, and clicking on it changes the image from greyscale to coloured, acting like a ToggleColumn. Everything works fine, just want to know how can I center align the column data instead of left aligned, I can set the position of column header but not the blocks below it. Here is a example image,
Image

As you can see, the column header shows in middle, but the blocks below it are left aligned, I want that they also show center aligned. I have tried using SetAlignment(wxALIGN_CENTER) but it does not seem to do anything, or perhaps it is for column header only.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

Can you check the "dataview" sample?

On the second tab, "MyListModel", the first column is an icon+text column. Under Windows it is center aligned.
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: Fri Jul 02, 2021 12:16 am Can you check the "dataview" sample?

On the second tab, "MyListModel", the first column is an icon+text column. Under Windows it is center aligned.
I just checked the dataview sample, it does not look like center aligned in the sample either, so is it not possible on Linux/GTK?
Image
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
Can you try and see if its possible to set the right alignment?

Also - what is your GTK+ version, theme and WM?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

Your sample looks different than mine. You're still on wx 3.0.5?
dataview-sample.png
dataview-sample.png (28.25 KiB) Viewed 1367 times
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 »

ONEEYEMAN wrote: Fri Jul 02, 2021 5:51 am Hi,
Can you try and see if its possible to set the right alignment?
I tried using SetAlignment(wxALIGN_RIGHT), looks like it only aligns the column header right, not the block below.
Image
ONEEYEMAN wrote: Fri Jul 02, 2021 5:51 am Also - what is your GTK+ version, theme and WM?
My GTK and wx version,
Image

Theme I'm using currently is the default GTK theme used, i.e Adwaita, I'm using dark version of it, I have multiple WM installed, in the screenshot above, I'm using a standalone WM called DWM. But I don't think WM should affect anything here.
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: Fri Jul 02, 2021 6:53 am Your sample looks different than mine. You're still on wx 3.0.5?

dataview-sample.png
Yes, the Git branch I'm currently working on, I'm still on wx 3.0.5, I will switch to wx 3.1.x, in a different branch, because this branch is temporary. I will try the sample for wx3.1.x, and see if that sample shows in center.
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: Fri Jul 02, 2021 6:53 am Your sample looks different than mine. You're still on wx 3.0.5?

dataview-sample.png
Yes on the sample for wx3.1.x source, the column items appear center aligned.
Image

I guess I got another reason to switch to wx3.1.x.

I also noticed widgets looked a bit different, the over feel, visually looked a bit different, more polished and cleaner. Is there some difference?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax »

Is there some difference?
I'm pretty sure there are many differences, 3.0.5 is over a year old. Maybe the improved dark mode support is what you're seeing.
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: Fri Jul 02, 2021 6:53 am Your sample looks different than mine. You're still on wx 3.0.5?

dataview-sample.png
Okay, I built the application with wx3.1.5,
Image

But it still does not show center aligned,
Image

Here is the code, where I append the columns,

Code: Select all

    m_SampleListView->AppendIconTextColumn((wchar_t)U'🟊', 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);
    m_SampleListView->AppendTextColumn("Type", wxDATAVIEW_CELL_INERT, 120, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
    m_SampleListView->AppendTextColumn("Channels", wxDATAVIEW_CELL_INERT, 100, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
    m_SampleListView->AppendTextColumn("Length", wxDATAVIEW_CELL_INERT, 100, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
    m_SampleListView->AppendTextColumn("Sample Rate", wxDATAVIEW_CELL_INERT, 140, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);
    m_SampleListView->AppendTextColumn("Bitrate", wxDATAVIEW_CELL_INERT, 100, wxALIGN_RIGHT, wxDATAVIEW_COL_RESIZABLE | wxDATAVIEW_COL_SORTABLE);

    m_SampleListView->GetColumn(0)->SetAlignment(wxALIGN_CENTER);
And the icon there is PNG image, which I insert like this,

Code: Select all


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

        if (tags.IsFileValid())
        {
            data.clear();
            data.push_back(icon);
            data.push_back(filename);
 .
 .
 .
 
Also I'm getting this assert message every time I open the application, I did not get these before when I was using wx.3.0.5
Image

I also noticed quite a few things, that was not working before started working now, like before wxLogInfo() and wxLogWarning() was not working, i.e nothing shows up, only wxLogDebug() worked, now wxLogInfo(0 and wxLogWarning() are showing up as well.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
So what do you do differently from the sample?
Can you isolate it, i.e. make the sample work like your application?

Thank you.
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 »

ONEEYEMAN wrote: Fri Jul 02, 2021 9:55 pm Hi,
So what do you do differently from the sample?
Can you isolate it, i.e. make the sample work like your application?

Thank you.
Looking at the code for the dataview sample, it looks like it is using a custom column that uses CheckIconTextRenderer instead of IconTextRenderer,

Code: Select all

            wxDataViewColumn* const colCheckIconText = new wxDataViewColumn
                (
                     L"\u2714 + icon + text",
                     new wxDataViewCheckIconTextRenderer(),
                     MyListModel::Col_ToggleIconText,
                     wxCOL_WIDTH_AUTOSIZE
                );
            m_ctrl[Page_List]->AppendColumn(colCheckIconText);
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
Then all you meed to do is use it, right? ;-)

Thank you.
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 »

ONEEYEMAN wrote: Fri Jul 02, 2021 10:41 pm Hi,
Then all you meed to do is use it, right? ;-)

Thank you.
Yes, but I don't want the checkbox in that column, that is why I switched from ToggleColumn to IconTextColumn.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN »

Hi,
Yes, But you can override the renderer and use the icon instead.

Thank you.
Post Reply