How to change wxRadioBox labels colors

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
neglio
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 11, 2009 10:10 am

How to change wxRadioBox labels colors

Post by neglio »

Hi,
i have to change the color of the radio buttons label in a wxRadioBox, but can only change the color of the wxRadioBox description. How can I do?

I ve tried the following code, but it does not work :

Code: Select all

_toolbar->SetBackgroundColour(*wxBLACK);
_toolbar->SetForegroundColour(*wxWHITE);
wxString radioButtonsLabels[] = {_("Label 1"),_("Label 2")};
_itemRadioBox = new wxRadioBox( _toolbar, -1, _("RadioBox"), wxDefaultPosition, wxDefaultSize, 2, radioButtonsLabels, 1, wxRA_SPECIFY_COLS );
_itemRadioBox->SetSelection(0);
_itemRadioBox->SetBackgroundColour(*wxBLACK);
_itemRadioBox->SetForegroundColour(*wxWHITE);
_toolbar->AddControl(itemRadioBox );

And also the following code did not work:

Code: Select all

void SetWindowForegroundColour(wxWindow *wnd, const wxColour &col)
{
   if(wnd)
   {
     wxButton *btn = wxDynamicCast(wnd, wxButton);
     if(!btn) 
       wnd->SetForegroundColour(col);

     // get every window, and make the foreground equal to the given one
     wxWindowListNode *node = wnd->GetChildren().GetFirst();
     while (node)
     {
       SetWindowForegroundColour(node->GetData(), col);
       node = node->GetNext();
     }
   }
}

_toolbar->SetBackgroundColour(*wxBLACK);
_toolbar->SetForegroundColour(*wxWHITE);
wxString radioButtonsLabels[] = {_("Label 1"),_("Label 2")};
_itemRadioBox = new wxRadioBox( _toolbar, -1, _("RadioBox"), wxDefaultPosition, wxDefaultSize, 2, radioButtonsLabels, 1, wxRA_SPECIFY_COLS );
_itemRadioBox->SetSelection(0);
_itemRadioBox->SetBackgroundColour(*wxBLACK);
_itemRadioBox->SetForegroundColour(*wxWHITE);
SetWindowForegroundColour(_itemRadioBox,*wxWHITE);
_toolbar->AddControl(itemRadioBox );
SetWindowForegroundColour(_toolbar,*wxWHITE);
Could someone help me please?
krishnaprasad
Experienced Solver
Experienced Solver
Posts: 77
Joined: Tue Oct 21, 2008 6:07 pm

Post by krishnaprasad »

What OS you are using ? On Mac AFAIK you cant change the native look and feel.
neglio
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 11, 2009 10:10 am

Post by neglio »

Hi,
i use Windows XP 32 bit and 64 bit.
Do you know what i have to do?
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester »

krishnaprasad wrote:What OS you are using ? On Mac AFAIK you cant change the native look and feel.
On Mac You can use carbon for access many unavailable from wxWidgets properties
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester »

Maybe just use wxStaticBoxSizer + wxRadioButtons?
neglio
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 11, 2009 10:10 am

Post by neglio »

lester wrote:Maybe just use wxStaticBoxSizer + wxRadioButtons?
is there no way to do it with wxRadioBox?
lester
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 211
Joined: Sat Sep 02, 2006 7:24 pm
Location: Ukraine

Post by lester »

neglio wrote:
lester wrote:Maybe just use wxStaticBoxSizer + wxRadioButtons?
is there no way to do it with wxRadioBox?
src/msw/radiobox.cpp

Code: Select all

....
    m_radioButtons = new wxSubwindows(n);
    m_radioWidth = new int[n];
    m_radioHeight = new int[n];

    for ( int i = 0; i < n; i++ )
    {
        m_radioWidth[i] =
        m_radioHeight[i] = wxDefaultCoord;
        long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
        if ( i == 0 )
            styleBtn |= WS_GROUP;

        long newId = NewControlId();

        HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
                                      choices[i],
                                      styleBtn,
                                      0, 0, 0, 0,   // will be set in SetSize()
                                      GetHwndOf(parent),
                                      (HMENU)newId,
                                      wxGetInstance(),
                                      NULL); 

...
so You must use WinAPI or wxStaticBoxSizer + wxRadioButtons
neglio
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 11, 2009 10:10 am

Is that a bug of wxRadioButton ?

Post by neglio »

I've tried to use wxStaticBox + wxRadioButton to realize a radiobox, but i still have no way to change the label color of a wxRadioButton.

I use wxWidgets.2.8.10 on WinXP 32 bit, and radioButtonb1->SetForegroundColour(*wxWHITE) seems no work.

Is that a bug of wxRadioButton ?
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

lester wrote: src/msw/radiobox.cpp

Code: Select all

....
    m_radioButtons = new wxSubwindows(n);
    m_radioWidth = new int[n];
    m_radioHeight = new int[n];

    for ( int i = 0; i < n; i++ )
    {
        m_radioWidth[i] =
        m_radioHeight[i] = wxDefaultCoord;
        long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
        if ( i == 0 )
            styleBtn |= WS_GROUP;

        long newId = NewControlId();

        HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
                                      choices[i],
                                      styleBtn,
                                      0, 0, 0, 0,   // will be set in SetSize()
                                      GetHwndOf(parent),
                                      (HMENU)newId,
                                      wxGetInstance(),
                                      NULL); 

...
so You must use WinAPI or wxStaticBoxSizer + wxRadioButtons
neglio
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 11, 2009 10:10 am

Post by neglio »

Excuse me, could you explain me what i have to understand from your posted code? What i have to do to change a label color?
Regards
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Post by Auria »

neglio wrote:Excuse me, could you explain me what i have to understand from your posted code? What i have to do to change a label color?
Regards
I don't know the Windows API much, but from his comments I suppose it means they're always created with default colour :)
neglio
In need of some credit
In need of some credit
Posts: 6
Joined: Wed Mar 11, 2009 10:10 am

Post by neglio »

Ok, thanks. But, why doesn't the SetForegroundColour() method of wxRadioButton work?
Rayman
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Jul 16, 2008 9:48 pm
Contact:

Re: How to change wxRadioBox labels colors

Post by Rayman »

I'd like to bring this topic up again, since there is no change in the current WX version 3.0 using Windows 7.

Changing the foreground color of a wxRadioBox changes the top label of the wxRadioBox but the actual radio buttons inside the box remain black. This doesn't make any sense. If the user is not allowed to change the foreground color than the top label should not change as well ...

Is there a solution planned for this? I'd like to have a dark themed background, but my radiobuttons are black and therfore unreadable :-(
Post Reply