Page 1 of 1

Can't set wxChoice background color

Posted: Fri Jun 05, 2020 3:14 pm
by USB3pt0
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.

Re: Can't set wxChoice background color

Posted: Fri Jun 05, 2020 4:41 pm
by New Pagodi
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.

Re: Can't set wxChoice background color

Posted: Fri Jun 05, 2020 6:06 pm
Also, it might depend on the theme.

Thank you.