Get size of widget



I simply want to know which size a widget has. I need this info to set a ScrolledWindow to a maximum size if the size of the widget is bigger than the screen.

But all functions I know give a constant value of 1.

#include <iostream>
#include <gtkmm.h>
#include <gtkmm/window.h>

class ExampleWindow: public Gtk::Window
{
    Gtk::Button button;
    public:
    ExampleWindow(): button("Hallo")
    {
        add(button);
        GetSize();
    }

    void GetSize()
    {
std::cout << button.get_width() << " " << button.get_height() << std::endl; std::cout << button.get_allocated_width() << " " << button.get_allocated_height() << std::endl;
    }
};


int main(int argc, char* argv[])
{
    Gtk::Main kit(argc, argv);

    ExampleWindow window;

    window.GetSize();
    window.show_all_children();
    window.GetSize();
    Gtk::Main::run(window);
    return 0;
}


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