How to change the color of a CEikLabel

A CEikLabel is a basic component use to display static text in a control. It is fairly easy and straightforward to use as soon as you don't have to change its color: there is no SetColor() primitive.

If you are reading this page, you are probably looking for the answer. And as usual in the Symbian world, it is pretty trivial once you know how to do it. As a matter of fact, you have to override the EColorLabelTextEmphasis setting of your label using the OverrideColorL() primitive and then to activate the setting, using SetEmphasis(). The code below shows how to do this:

#include <gulcolor.h>
...
// Basic Label Construction
CEikLabel* myLabel;
myLabel= new (ELeave) CEikLabel;
myLabel->SetContainerWindowL( *this );
myLabel->SetTextL( _L("NewLC rulez!") );

// Now Set the foreground color to Red
myLabel->OverrideColorL( EColorLabelTextEmphasis, KRgbRed );
myLabel->SetEmphasis( CEikLabel::EPartialEmphasis );  

Alternatively you may want to specify a foreground AND a background color. In this case, you also have to override and activate the EColorLabelHighlightFullEmphasis setting:

// Now Set the foreground Color to White
// and the background color to Red
myLabel->OverrideColorL( EColorLabelTextEmphasis, KRgbWhite );
myLabel->OverrideColorL( EColorLabelHighlightFullEmphasis, KRgbRed );
myLabel->SetEmphasis( CEikLabel::EFullEmphasis );  


> How to change the color of a CEikLabel

is there also a way to change the foreground color in a CEikEdwin???

thanx in advance, daisy

> How to change the color of a CEikLabel

CCharFormatLayer* FormatLayer=CEikonEnv::NewDefaultCharFormatLayerL();

TCharFormat charFormat; TCharFormatMask charFormatMask; FormatLayer->Sense(charFormat, charFormatMask);

charFormat.iFontPresentation.iTextColor=KRgbBlue;

charFormatMask.SetAttrib(EAttColor);

FormatLayer->SetL(charFormat, charFormatMask);

iEdwin->SetCharFormatLayer(Format);

> How to change the color of a CEikLabel

i m trying to change the background color of a dialog n m able to change the background color of dialog using override color in its Prelayout function but when i put more controls like labels in it the background of label is again white n i tried to change its color using overridel in prelayout fn of dialog but it dint work.I can change the color of text but not of background of label in dialog.I tried ECOntrolBackground in overrideL fn for label but this too dint work? how can i do this ? plz guide thks n rgds

> How to change the color of a CEikLabel

But when you don't call the follow function,there is a default backgroud color black!my sdk is uiq 2.1.

And when you don't call these two fuction,u can get a transparent label! But i want get a transparent label with self def foregroud color, do u have a idea?

myLabel->OverrideColorL( EColorLabelHighlightFullEmphasis, KRgbRed );

> How to change the color of a CEikLabel

This does not seem to work anymore on UIQ3. Any suggestions?

> How to change the color of a CEikLabel

I was able to solve this on UIQ3 by implementing GetTextDrawer in the container that owns the label. In the end it wasn't too complicated but I want to note that they don't make it simple for you at all. I wonder why they kept OverrideColorL/SetEmphasis if they don't do what they are supposed to.

I noticed that on Symbian, especially on new platforms like S60 3rd or UIQ 3 the developer is spending A LOT of time trying to figure out simple things as opposed to concentrating on the application. Estimating the time required for a Symbian project is never a simple issue.

Re: > How to change the color of a CEikLabel

Thanks for the notes

Will u pls, tell me What exactly is setting Emphsis, setting it partial, here?
How do we set the alignment to center or right of the label with out explicitly specifyiing the positions in pixels.

Regards,
Netra

> How to change the color of a CEikLabel

Nice & easy, thanx!

> How to change the color of a CEikLabel

when I use the

myLabel->OverrideColorL( EColorLabelTextEmphasis, KRgbRed ); myLabel->SetEmphasis( CEikLabel::EPartialEmphasis );

where I got it from this forum, my emulator got hang, but it can be compiled and built though. Can anyone tell me what's wrong?

thank you

> How to change the color of a CEikLabel

when I use the

myLabel->OverrideColorL( EColorLabelTextEmphasis, KRgbRed ); myLabel->SetEmphasis( CEikLabel::EPartialEmphasis );

where I got it from this forum, my emulator got hang, but it can be compiled and built though. Can anyone tell me what's wrong?

thank you

> How to change the color of a CEikLabel

I got it right like this,

CEikLabel* iLabel = (CEikLabel*)dlg->Control(EMyFormCtrlLabel); _LIT(ltext, " Enter the Mobile Number "); iLabel->SetTextL(ltext); iLabel->OverrideColorL( EColorLabelTextEmphasis, KRgbRed ); iLabel->SetEmphasis( CEikLabel::EPartialEmphasis ); iLabel->OverrideColorL( EColorLabelTextEmphasis, KRgbWhite ); iLabel->OverrideColorL( EColorLabelHighlightFullEmphasis, KRgbRed ); iLabel->SetEmphasis( CEikLabel::EFullEmphasis );

This worked well on my emulator.

> How to change the color of a CEikLabel

It's a pity that these methods can't keep the label transparent ! Any one has a idea about changing the label text color and keeping the label transparent together?

> How to change the color of a CEikLabel

try myLabel->SetBrushStyle(CWindowGc::ENullBrush);

> How to change the color of a CEikLabel

Never seen a SetBrushStyle(CWindowGc::ENullBrush); fuction in CEikLabel class.

Bad class i'd ever seen!

How to change the color of a CEikLabel

If you use the below class instead of CEikLabel,you will change the text color and keep the label transparent together,this means there can be a picture under the label.

class CNewLabel: public CEikLabel public:

void Draw(const TRect& aRect) const CWindowGc & gc = SystemGc(); gc.SetBrushStyle( CGraphicsContext::ENullBrush ); //CEikLabel::Draw(aRect);

gc.UseFont(iFont); TRgb rgb; GetColor(EColorLabelTextEmphasis,rgb); gc.SetPenColor(rgb); TRect textRect(Rect()); //textRect.Shrink(4,2); TInt baseline = textRect.Height()/2+iFont->AscentInPixels()/2; gc.DrawText(iText->Des(),textRect,baseline); gc.DiscardFont(); ;

goready.