Page 1 of 1

How to change wxRadioBox labels colors

Posted: Wed Mar 11, 2009 11:41 am
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?

Posted: Thu Mar 12, 2009 8:26 pm
by krishnaprasad
What OS you are using ? On Mac AFAIK you cant change the native look and feel.

Posted: Thu Mar 12, 2009 8:39 pm
by neglio
Hi,
i use Windows XP 32 bit and 64 bit.
Do you know what i have to do?

Posted: Thu Mar 12, 2009 10:48 pm
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

Posted: Thu Mar 12, 2009 10:48 pm
by lester
Maybe just use wxStaticBoxSizer + wxRadioButtons?

Posted: Thu Mar 12, 2009 11:05 pm
by neglio
lester wrote:Maybe just use wxStaticBoxSizer + wxRadioButtons?
is there no way to do it with wxRadioBox?

Posted: Fri Mar 13, 2009 5:51 am
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

Is that a bug of wxRadioButton ?

Posted: Tue Mar 24, 2009 12:37 pm
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 ?

Posted: Tue Mar 24, 2009 2:56 pm
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

Posted: Tue Mar 24, 2009 3:42 pm
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

Posted: Tue Mar 24, 2009 3:54 pm
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 :)

Posted: Tue Mar 24, 2009 4:17 pm
by neglio
Ok, thanks. But, why doesn't the SetForegroundColour() method of wxRadioButton work?

Re: How to change wxRadioBox labels colors

Posted: Fri May 16, 2014 9:23 am
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 :-(