RE: How to get the widget's current width and height?



To get the current widget size need a reason? Sorry to say that but
there are a lot of reasons. Sizes and positions are basic stuff!

For example: I have a widget dynamicly draw a clock, I want the clock 
Just fit into the widget, I need the size information every minutes.

Sure, I can connect the size alloc and remember the size by myself.
But...

Thanks iain just told me:
        GTK_WIDGET (widget)->allocation.width;
        GTK_WIDGET (widget)->allocation.height;
This code works! And thanks GTK+ use C so that we can access all the
private data they have.











-----Original Message-----
From: John K Luebs [mailto:jkluebs luebsphoto com] 
Sent: Tuesday, November 18, 2003 11:52 PM
To: Tom Liu
Cc: gtk-app-devel-list gnome org
Subject: Re: How to get the widget's current width and height?

On Tue, Nov 18, 2003 at 09:29:50AM -0500, Tom Liu wrote:
gdk_drawable_get_size(w->window,&wid,&hi); may work for the widget
which
has a xwindow such as eventbox. For vbox, label, button etc. It will
not
work.
Can't believe there is no function to retrive size of widget?!


There is a good reason for this. The size of a widget (it's allocation) 
is dynamic (can be changed by the user, WM, etc.), so having a function
to query the current size would just facilitate writing fundamentally
broken code. There's no point in getting a value that could become
invalid the moment you return to the mainloop.

As another poster has told you, you should connect to size-allocate.
This way you know that you always have the correct size, and can react
appropriately.

You should also take a moment to think about why you need the size.
Are you sure this is not something you can do in a more
straightforward manner using the packing mechanisms?

--jkl




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