Package: gtk
Class gtk-image
SuperclassesDocumented Subclasses
None
Direct SlotsDetails The gtk-image widget displays an image.
Various kinds of objects can be displayed as an image. Most typically, you would load a gdk-pixbuf object from a file, and then display that. There is a convenience gtk-image-new-from-file function to do this, used as follows: (let ((image (gtk-image-new-from-file "myfile.png"))) ... )If the file is not loaded successfully, the image will contain a "broken image" icon similar to that used in many web browsers. If you want to handle errors in loading the file yourself, for example by displaying an error message, then load the image with the gdk-pixbuf-new-from-file function, then create the gtk-image widget with the gtk-image-new-from-pixbuf function. The image file may contain an animation, if so the gtk-image widget will display a gdk-pixbuf-animation object instead of a static image. The gtk-image class is a subclass of the gtk-misc class, which implies that you can align it (center, left, right) and add padding to it, using the gtk-misc methods. The gtk-image widget is a "no window" widget (has no GDK window of its own), so by default does not receive events. If you want to receive events on the image, such as button clicks, place the image inside a gtk-event-box widget, then connect to the event signals on the event box. Example(defun create-image () (let ((image (gtk-image-new-from-file (rel-path "ducky.png"))) (event-box (make-instance 'gtk-event-box))) ;; Set the event mask for the event box (setf (gtk-widget-events event-box) :button-press-mask) ;; Connect a signal to the event box (g-signal-connect event-box "button-press-event" (lambda (box event) (declare (ignore box)) (format t "Event box clicked at : ~6,2f, ~6,2f~%" (gdk-event-button-x event) (gdk-event-button-y event)) +gdk-event-stop+)) ;; Add the image to the event box (gtk-container-add event-box image) ;; Return the event box with the image event-box))When handling events on the event box, keep in mind that coordinates in the image may be different from event box coordinates due to the alignment and padding settings on the image, see the gtk-misc class. The simplest way to solve this is to set the alignment to 0.0 (left/top), and set the padding to zero. Then the origin of the image will be the same as the origin of the event box. CSS nodes | Slot Access FunctionsInherited Slot Access FunctionsSee also |
*2021-12-17