As an indication that the user needs to set a value, I would like to set the background colour on certain input-controls to e.g. yellow.
This works fine for wxTextCtrl, but for wxChoice the colour remains the same.
Anyone out there with an idea of how to fix this - or perhaps give the user a hint that a wxChoice needs to be filled out?
BR
Peter
Setting the background color in wxChoice
Re: Setting the background color in wxChoice
I feel there is no direct API to do it.
But you can use the following trick implement the desire behaviour.
But you can use the following trick implement the desire behaviour.
Code: Select all
#include <wx/artprov.h>
m_pSizer = new wxBoxSizer(wxHORIZONTAL);
wxChoice* pChoice = new wxChoice(this, wxID_ANY);
pChoice->AppendString("One");
pChoice->AppendString("Two");
pChoice->AppendString("Three");
m_pSizer->Add(pChoice);
pChoice->Bind(wxEVT_PAINT, [=](wxPaintEvent& event){
wxPaintDC dc(pChoice);
wxRect rect(0, 0, dc.GetSize().GetWidth(), dc.GetSize().GetHeight());
dc.SetBrush(*wxYELLOW_BRUSH);
dc.SetPen(*wxGREY_PEN);
dc.DrawRectangle(rect);
dc.DrawBitmap(wxArtProvider::GetBitmap(wxART_GO_DOWN, wxART_OTHER, wxSize(10, 10)), wxPoint(rect.GetWidth() - 15, (rect.GetHeight() / 2) - 5));
const wxString sel = pChoice->GetStringSelection();
if (!sel.IsEmpty())
{
dc.DrawLabel(sel, rect, wxALIGN_CENTER_VERTICAL);
}
});
- evstevemd
- Part Of The Furniture
- Posts: 2409
- Joined: Wed Jan 28, 2009 11:57 am
- Location: United Republic of Tanzania
Re: Setting the background color in wxChoice
This is not what you asked for but as an alternative, you could disable all other control that depend on that wxChoice until user selects it. Also you could enable them and when user tries to access something that depends on that choice control send them to choice control and show a tooltip that they cannot do that until they fill the choice.pkl wrote:As an indication that the user needs to set a value, I would like to set the background colour on certain input-controls to e.g. yellow.
This works fine for wxTextCtrl, but for wxChoice the colour remains the same.
Anyone out there with an idea of how to fix this - or perhaps give the user a hint that a wxChoice needs to be filled out?
BR
Peter
I would go for the latter as it is user friendly.
NOW to answer your question is some native controls don't allow such kind of changes. There are generic widgets that are not native and you can have look at them and see if it is what you want: https://github.com/wxWidgets/wxWidgets/ ... wx/generic
Chief Justice: We have trouble dear citizens!
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Citizens: What it is his honor?
Chief Justice:Our president is an atheist, who will he swear to?
Re: Setting the background color in wxChoice
Hi,
What is your platform/toolkit?
Is it possible to change it to use wxComboBox?
Thank you.
What is your platform/toolkit?
Is it possible to change it to use wxComboBox?
Thank you.
Re: Setting the background color in wxChoice
Thank you for your replies. I have been on vacation and not had time to persue this further before now. I will try to implement the solution suggested by Amil or perhaps OneEyeMan.
EvStevemds solution can not be used in my application because it is more complex than that. A choice might be part of a group of controls where either all or no controls should be filled out. Thus, filling out a text-field or a listcontrol might require the choice to need input.
My platform is Linux and Windows.
Best regards
Peter
EvStevemds solution can not be used in my application because it is more complex than that. A choice might be part of a group of controls where either all or no controls should be filled out. Thus, filling out a text-field or a listcontrol might require the choice to need input.
My platform is Linux and Windows.
Best regards
Peter
Re: Setting the background color in wxChoice
Hello again,
So amils suggestion does not work well enough - the control becomes clearly non-standard. But thank you for the suggestion.
I will check the documentation for wxComboBox next.
Best regards
Peter
So amils suggestion does not work well enough - the control becomes clearly non-standard. But thank you for the suggestion.
I will check the documentation for wxComboBox next.
Best regards
Peter