2

I am trying to insert an image into a header bar in GTK4. The image should fit the height of the parent widget. In gtk4-rs I tried:

let image = gtk::Picture::builder()
        .hexpand(false)
        .vexpand(false)
        .halign(gtk::Align::Fill)
        .valign(gtk::Align::Fill)
        .keep_aspect_ratio(true)
        .can_shrink(true)
        .build();

Although can_shrink(true) is set, the image causes the header to grow. I also tried .height_request(1).width_request(1), but that also had no effect.

How can I make the image fit the header's size determined by the other widgets in the header?

1 Answers1

0

maybe it is too late but, have you tried setting the content_fit property with gtk::ContentFit::ScaleDown? To do that, you'd need to enable the feature v4_8 on your Cargo.toml file like gtk4 = { version = "0.6.6", features = ["v4_8"] }

Jayson Reis
  • 708
  • 5
  • 14