wxDataViewListCtrl: Change the background color for selectedrows? 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
User avatar
ColleenKobe
Experienced Solver
Experienced Solver
Posts: 88
Joined: Mon Aug 31, 2015 3:47 pm

wxDataViewListCtrl: Change the background color for selectedrows?

Post by ColleenKobe » Thu Jan 25, 2018 8:47 pm

I've created a wxDataViewListCtrl. When the program runs, some rows will have active data, and some rows will have "inactive" data.

Is there a way that I can change the background color of the inactive rows to gray? Assume the background color would "key off" one of the fields. I do know about the wxDV_HORIZ_RULES, but that's every other row no matter what the contents of the row are.

Thanks!

Colleen

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4360
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxDataViewListCtrl: Change the background color for selectedrows?

Post by ONEEYEMAN » Thu Jan 25, 2018 9:33 pm

Hi,
Didi you look at the 'dataview' sample?

Thank you.

User avatar
ColleenKobe
Experienced Solver
Experienced Solver
Posts: 88
Joined: Mon Aug 31, 2015 3:47 pm

Re: wxDataViewListCtrl: Change the background color for selectedrows?

Post by ColleenKobe » Fri Jan 26, 2018 3:57 pm

Thank you for answering, OneEyeMan.

Yes, I looked at the wxDataViewCtrl sample. There was a tab there showing a wxDataViewListCtrl, but all the rows had a white background.

There was also a tab called MyListModel with different colors of text, but the row backgrounds were also all white.

Colleen

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

Re: wxDataViewListCtrl: Change the background color for selectedrows?

Post by doublemax » Fri Jan 26, 2018 4:57 pm

As usual, a look into the sources reveals the ultimate truth... ;)

Under Windows wxDVC uses wxRendererNative::Get().DrawItemSelectionRect() to draw the cell background...

Code: Select all

    wxBrush brush;
    if ( flags & wxCONTROL_SELECTED )
    {
        if ( flags & wxCONTROL_FOCUSED )
        {
            brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
        }
        else // !focused
        {
            brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
        }
    }
    else // !selected
    {
        brush = *wxTRANSPARENT_BRUSH;
    }
... and that uses system colors for the background with no simple way to override them.
Use the source, Luke!

User avatar
ColleenKobe
Experienced Solver
Experienced Solver
Posts: 88
Joined: Mon Aug 31, 2015 3:47 pm

Re: wxDataViewListCtrl: Change the background color for selectedrows?

Post by ColleenKobe » Mon Jan 29, 2018 12:58 pm

Doublemax,

Thank you for investigating the background color issue for me. I wouldn't have known where to START looking.

It sounds like changing the background color in a wxDataViewListCtrl involves more time and energy than the results warrant. Too bad, but OK.

Thanks again!

Colleen

Post Reply