Re: resizing a drawingarea



On 10/04/11 14:54, Kees Kling wrote:
> On 04/10/2011 02:43 PM, Robert Pearce wrote:
>> Hi Kees,
>>
>> On Sun, 10 Apr 2011 11:19:01 +0200 you wrote:
>>> On 04/10/2011 10:30 AM, Povietkin Konstantin wrote:
>>>> В Вск, 10/04/2011 в 08:53 +0200, Kees Kling пишет:
>>>>> I have a widget derived from Gtk::DrawingArea. This widget is placed in
>>>>> a window. So far so good, but when I resize the window, the size of the
>>>>> drawingarea stays the same. What must I do about that.
>>>>>
>>>> You should use Gtk::Viewport.
>>> Do you mean deriving from Gtk::Viewport or adding the widget to a
>>> viewport, because the latter doesn't work for me
>>>
>> I can't imagine why Konstantin thought a viewport was what you need. A
>> viewport is a device for making a large unshrinkable widget fit in a
>> small window by adding scroll bars.
>>
>> Unless I'm mistaken, a DrawingArea just presents somewhere to use the
>> graphics primitives. It has very little inherent functionality. I
>> assume you're using the on_expose_event hook to do some drawing? I
>> think for resizing you will need to do something in the
>> on_size_allocate hook too. And you'll need to modify the drawing
>> algorithms in on_expose_event to take account of the new size.
>>
>>
>> HTH,
>>
>> Rob
>> _______________________________________________
>> gtkmm-list mailing list
>> gtkmm-list gnome org
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
> Yes i'm using on_expose_event tyo do the drawing and I also has
> 
> the "virtual void on_size_allocate(Gtk::Allocation& allocation);" 
> method. In this method I call ste_allocation(allocation) and I check on 
> several places in my code what the geometry of the widget is and these 
> are correct, but my drawingArea keeps its orginal  size.

What I always do, which seems to always work :) , is in the expose_event
handler, do something like the following:

bool MyWidget::_on_expose_event(GdkEventExpose* event) {
    int x = get_allocation().get_x();
    int y = get_allocation().get_y();
    int width = get_allocation().get_width();
    int height = get_allocation().get_height();

And then use these variables in any functions in that expose event
handler, eg.

     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);

Hope this helps

-- 
Andrew


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