Re: Get size of widget
- From: Kjell Ahlstedt <kjellahlstedt gmail com>
- To: Klaus Rudolph <lts-rudolph gmx de>
- Cc: gtkmm-list gnome org
- Subject: Re: Get size of widget
- Date: Tue, 26 Dec 2017 15:16:29 +0100
I modified your example, adding on_button_realize(). The output becomes
1 1
1 1
1 1
1 1
1 1
1 1
Button has been realized: 49 29
49 29
All your calls to GetSize() occur before the button is realized.
#include <iostream>
#include <gtkmm.h>
#include <gtkmm/window.h>
class ExampleWindow: public Gtk::Window
{
Gtk::Button button;
public:
ExampleWindow(): button("Hallo")
{
add(button);
GetSize();
button.signal_realize().connect(sigc::mem_fun(*this,
&ExampleWindow::on_button_realize));
}
void GetSize()
{
std::cout << button.get_width() << " " << button.get_height()
<< std::endl;
std::cout << button.get_allocated_width() << " " <<
button.get_allocated_height() << std::endl;
}
void on_button_realize()
{
std::cout << "Button has been realized: ";
GetSize();
}
};
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;
}
On 2017-12-26 14:59, Phil Wolff wrote:
A widget's size is negotiated when it is realized. As in one of your
other questions, signal_realized() should help.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]