RE: Trouble with Gtk::EventBox and Expose Events



Hi,

I have a Gtk::Label and behind it I want to have a rectangle filled with
the Base colour from the user's GTK theme (white) and a shadow as a
border (http://i.imgur.com/fx8te.png)

I have tried to achieve this by packing the Gtk::Label into a
Gtk::EventBox and then connecting to the EventBox's signal_expose_event.
In this callback, I then draw the rectangle (using cairo) and draw the
shadow using Gtk::Style::paint_shadow. (The code is at the end of this
message)

However what happens is that the EventBox drawing seems to happen 'on
top' of the label, and so covers the label (http://i.imgur.com/tFFGK.png)

How can I stop this happening/if I can't, is there a better way to do this?

Thanks,
-- 
Andrew



----

BaseBox::BaseBox() : Gtk::EventBox()
{
    signal_expose_event().connect(sigc::mem_fun(*this,
&BaseBox::_on_expose_event));
    set_visible_window(false);
}

bool BaseBox::_on_expose_event(GdkEventExpose* event)
{
    Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context();

    // Draw background and shadow
    int x = get_allocation().get_x();
    int y = get_allocation().get_y();
    int width = get_allocation().get_width();
    int height = get_allocation().get_height();
    Gdk::Color background_fill = get_style()->get_base(get_state());

    cr->rectangle(x, y, width/4, height); // width/4 to show issue
    Gdk::Cairo::set_source_color(cr, background_fill);
    cr->fill();

    get_style()->paint_shadow(get_window(), get_state(), Gtk::SHADOW_IN,
        Gdk::Rectangle(x, y, width, height),
        *this, Glib::ustring::ustring("viewport"), x, y, width, height);

    return false;
}


[...]
BaseBox *basebox_no_search_results = new BaseBox();
label_not_found = new Gtk::Label();
[...]
basebox_no_search_results->add(*label_not_found);
notebook_content->insert_page(*basebox_no_search_results,
    NOTEBOOK_PAGE_NOT_FOUND);

----


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