Re: [gtkmm] How to change fontcolor in a Listview



Hi!

bart wrote:

I suppose the subject is obvious. I have a listview with a lot of names.
Some should be red and others green. Is there a way to do this?
I;ve looked in the CellRendering info, but i didn't find an answer
there.


Obviously you didn't look hard enough, because the answer is right there. CellRendererText has all sorts of properties for colors, text style, font, etc...

I think a convenient way to customize a text cells properties "on the fly" is through a user data function, which is called after the cell renderer properties have been set, but before the cell is rendered.

For example:


    Gtk::CellRenderer* cell_renderer =
        my_column->get_first_cell_renderer();

    my_column->set_cell_data_func(*cell_renderer,
        SigC::slot(*this, &MyWindow::cellDataFunc));



void MyWindow::cellDataFunc(Gtk::CellRenderer* cell_renderer,
    const Gtk::TreeModel::iterator& row)
{
    Gtk::CellRendererText* cell_renderer_text;

    if (cell_renderer_text =
        dynamic_cast<Gtk::CellRendererText*>(cell_renderer)) {

        cell_renderer_text->property_foreground() =
            (*row)[myModelColumns.color];
    }
}




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]