Can't get gtk::HeaderBar to show close (x) button

Hello everyone,

I’m currently learning how to use gtk-rs. I’m playing around with the gtk::HeaderBar, but I am having trouble getting the close (x) button to appear. This is how it currently looks:

image

I read online that the set_decoration_layout allows to have the close button show. I added header_bar.set_decoration_layout(Some("menu:minimize,close")); but that didn’t seem help.

I am not sure what I am doing doing wrong here… I provided the code below for you to see.

extern crate gtk;
extern crate gio;

use gtk::prelude::*;
use gio::prelude::*;

use gtk::{Application, ApplicationWindow, HeaderBar};

fn main() {
    let application = Application::new(
        None,
        Default::default(),
    ).expect("failed to initalize GTK application");

    application.connect_activate(|app| {
        let window = ApplicationWindow::new(app);
        window.set_default_size(350, 70);

        let header_bar = HeaderBar::new();
        header_bar.set_title(Some("My HeaderBar"));
        header_bar.set_decoration_layout(Some("menu:minimize,close"));

        window.set_titlebar(Some(&header_bar));
        window.show_all();
    });

    application.run(&[]);
}

I think for GTK4 the close button is there by default, see

http://ssalewski.de/gtkprogramming.html#_headerbar

I figured it out. There is a method called set_show_close_button. If you set it to true, the buttons will show.

image

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.