Search code examples
windowgtksignalsgtkmm

Fitting image to window - GTKmm


I am writing a simple photo viewer in C++ using gtkmm and I can not sort out few things. I would like to fit the image which is displayed to window. To do do this, I have connected signal_configure_event to my fitting function. This works quite well, but now I have two another problems:

  1. The signal is not sent while maximizing/minimizing the window, and image size is not updating. I have tried to fix this by connecting my resize function to signal_window_state_event, but it does not work because signal is sent before resizing the window and running my function makes no sense because it gets old Gtk::Image widget size parameters.

  2. Similiar story is with loading first image while launching my app - when I connect loadImage() to signal_show of main window it is launched before the window is maximized and the image remains very small.

If anyone could give me some idea on how to do it properly, I will be very grateful. GTKmm documentation is really poor and I have no idea how to do it.

Code responsible for above actions is here (the rest is in the repository): https://github.com/jjkrol/ZPR/blob/master/src/gui.cpp

Thank you very much in advance.


Solution

  • The solution was to connect my function to signal_size_allocate, any other signal is unnecessary now. Thanks ergosys!