Getting wxColour from wxColourProperty

273 views
Skip to first unread message

Carsten Fuchs

unread,
Apr 30, 2010, 5:46:22 AM4/30/10
to wx-u...@googlegroups.com
Hi all,

using wx 2.9.1 and reading header file wxWidgets\include\wx\propgrid\advprops.h, I'm wondering
what the correct way is to get a wxColour from a wxColourProperty (that is available via a
wxPGProperty*).

That is, in

void WindowInspectorT::OnPropertyGridChanged(wxPropertyGridEvent& Event)
{
const wxPGProperty* Prop=Event.GetProperty();

wxString ColStr=Prop->GetValueAsString();
}


ColStr can be "(123, 0, 255)" but also "Blue", "White", "Navy", etc.
The problem is that
wxColour col1(ColStr);
seems to work when ColStr is one of the color names like "Blue", but is missing the "rgb" prefix
when it is of the form "(r, g, b)".
wxColour col2("rgb" + ColStr);
works when ColStr is of the form "(r, g, b)" but oviously not when it is a colour name.


Next, we could cast Prop to wxColourProperty, e.g. (untested)

const wxColourProperty* ColProp=dynamic_cast<const wxColourProperty*>(Prop);

if (ColProp)
{
wxColour col3=ColProp->GetColour(index);
}

but what is "index" supposed to mean??


Third option, calling Prop->GetValue() returns a wxVariant, which doesn't seem to help with
colours either.


In summary, when I want to obtain the wxColour that is defined by the wxColourProperty, what it
the "canoncial" way of doing so??

Many thanks for your help,
and best regards,
Carsten

--
Cafu - the open-source Game and Graphics Engine
for multiplayer, cross-platform, real-time 3D Action
Learn more at http://www.cafu.de

Jaakko Salli

unread,
Apr 30, 2010, 8:33:08 AM4/30/10
to wx-u...@googlegroups.com

Hi Carsten,

On 30.4.2010 12:46, Carsten Fuchs wrote:
> Hi all,
>
> using wx 2.9.1 and reading header file
> wxWidgets\include\wx\propgrid\advprops.h, I'm wondering what the correct
> way is to get a wxColour from a wxColourProperty (that is available via
> a wxPGProperty*).
>
[SNIP]
>
> Third option, calling Prop->GetValue() returns a wxVariant, which
> doesn't seem to help with colours either.
>
>
> In summary, when I want to obtain the wxColour that is defined by the
> wxColourProperty, what it the "canoncial" way of doing so??
>

I think the current recommended approach is to obtain wxColour
from the wxVariant value. Like this (see wxVariant documentation
for more info):

wxVariant value = Prop->GetValue();
wxColour col;
col << value;

Of course, with SVN trunk it is also possible to use wxAny
facilities ;)

Like this:

wxAny value = Prop->GetValue();
wxColour col = value.As<wxColour>();

HTH,
Jaakko

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+u...@googlegroups.com
or visit http://groups.google.com/group/wx-users

Carsten Fuchs

unread,
Apr 30, 2010, 10:50:46 AM4/30/10
to wx-u...@googlegroups.com
Hi Jaakko,

On 30.04.2010 14:33, Jaakko Salli wrote:
> wxVariant value = Prop->GetValue();
> wxColour col;
> col<< value;

Thanks for your quick reply, that works very well!

> Of course, with SVN trunk it is also possible to use wxAny
> facilities ;)
>
> Like this:
>
> wxAny value = Prop->GetValue();
> wxColour col = value.As<wxColour>();

I cannot easily upgrade to SVN trunk head, but I'm very much looking forward to the next 2.9.x
series release! :-)

Best regards,

Reply all
Reply to author
Forward
0 new messages