Can't set wxChoice background color

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
Earned a small fee
Earned a small fee
Posts: 18
Joined: Mon May 04, 2020 3:03 pm

Can't set wxChoice background color

Post by USB3pt0 » Fri Jun 05, 2020 3:14 pm

Hi all,

I'm currently changing around background and font colors in my program to be easier on the eyes, but wxChoice is fighting me.

The code to generate a wxChoice is as follows:

Code: Select all

wxString m_choiceBoxChoices[] = { wxT("default"), wxT("default") };
	int m_choiceBoxNChoices = sizeof( m_choiceBoxChoices ) / sizeof( wxString );
	m_choiceBox = new wxChoice( this, wxID_CHOICEDIALOGCHOICEBOX, wxDefaultPosition, wxSize( 300, -1 ), m_choiceBoxNChoices, m_choiceBoxChoices, 0 );
	m_choiceBox->SetSelection( 0 );
	choiceDialogSizer->Add( m_choiceBox, 0, wxALL, 5 );
Then the control is given colors to change background and font, like so:

Code: Select all

m_choiceBox->SetBackgroundColour(wxColour(0, 0, 204, 255));
		m_choiceBox->SetForegroundColour(wxColour(255, 255, 255, 255));
However, the Choice box and its dropdown arrow do not change color. When you click the dropdown, the options come up with the correct colors.

What do I have to change to change the color of the dropdown arrow/box as well?

Edit: This is 3.1.3 on MSW.

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 364
Joined: Tue Jun 20, 2006 6:47 pm

Re: Can't set wxChoice background color

Post by New Pagodi » Fri Jun 05, 2020 4:41 pm

Setting colors for native controls is usually not a good idea. It may not work or may not work as intended. Even if it works on one port, it may not work on other ports. As the documentation states:
Notice that as with SetForegroundColour(), setting the background colour of a native control may not affect the entire control and could be not supported at all depending on the control and platform.
If you want to set the appearance of a combobox, there's a generic control called wxOwnerDrawnComboBox that can be used instead. It's demonstrated in the combo sample.

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

Re: Can't set wxChoice background color

Post by ONEEYEMAN » Fri Jun 05, 2020 6:06 pm

Also, it might depend on the theme.

Thank you.

Post Reply