Modify the color of a TGTextLBEntry in a TGListBox

Hi,

How can I modify the color of an entry (in red for example) in a TGListBox ? I have succeed to modify the font using :

const TGFont *ufont;         // will reflect user font changes
ufont = gClient->GetFont("-adobe-courier-medium-r-*-*-18-*-*-*-*-*-iso8859-1");
if (!ufont)
   ufont = fClient->GetResourcePool()->GetDefaultFont();

TGGC   *uGC;           // will reflect user GC changes
// graphics context changes
GCValues_t val;
val.fMask = kGCFont;
val.fFont = ufont->GetFontHandle();
uGC = gClient->GetGC(&val, kTRUE);

TGTextLBEntry *entry;
char tmp[20];
for (int i = 0; i < 10; ++i) {
   sprintf(tmp, "Entry %i", i+1);
   entry = new TGTextLBEntry(fHistoryBox->GetContainer(), new TGString(tmp), i*10, uGC->GetGC(), ufont->GetFontStruct());
   fHistoryBox->AddEntry((TGLBEntry *)entry, new TGLayoutHints(kLHintsTop | kLHintsLeft));
}

But I have no idea if it is possible to modify the color.

Thanks in advance

Hi,

Not sure… I’ll check and let you know.

Cheers, Bertrand.

Try (for example):

   entry->SetBackgroundColor((Pixel_t)0xd0ffd0);

And BTW, you should also add kLHintsExpandX when adding the entry:

fListBox->AddEntry((TGLBEntry *)entry, new TGLayoutHints(kLHintsTop | kLHintsLeft |
                                                         kLHintsExpandX));

See for example:
image

Cheers, Bertrand.

Hi,

Thank you for the help. But this change the background, not the text color. BTW it could be ok for me, but how can I do know what adress corresponds to what color ? (0xd0ffd0 for green I guess in your example)

J.

Oh sorry, I overlooked at your question… I’ll check and let you know. And in my example, I simply used the hexadecimal representation of the color (RGB)

So strangely enough, you cannot change the text color (only the background)…

Cheers, Bertrand.

Ok, does’nt matter. Thank’s for the help

J.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.