【发布时间】:2017-12-26 09:03:24
【问题描述】:
我只是想知道小部件的尺寸。如果小部件的大小大于屏幕,我需要此信息将 ScrolledWindow 设置为最大大小。
但我知道的所有函数都给出一个常数值 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;
}
【问题讨论】:
-
附注,如果对您有用的话:
#include<gtkmm.h>已经处理了#include<gtkmm/window.h>。