I want to change the size of gtk_file_chooser_dialog_new() in GTK.

Asked 2 years ago, Updated 2 years ago, 108 views

The built-in GUI uses GTK.Output is 640x480 LCD panel.
When I used the file selection dialog in gtk_file_chooser_dialog_new() to select a file, the dialog is sticking out the LCD display and I can't see the whole thing.

/*Create File Selection Dialog*/
dialog=gtk_file_chooser_dialog_new("Open an image",
    GTK_WINDOW(m_window),
    GTK_FILE_CHOOSER_ACTION_OPEN,
    GTK_STOCK_CANCEL,
    GTK_RESPONSE_CANCEL,
    GTK_STOCK_OPEN,
    GTK_RESPONSE_ACCEPT,
    NULL);

gtk_widget_set_size_request(dialog,320,240);

/* View Dialog*/
gtk_widget_show_all(dialog);

I tried, but I couldn't change the size as I wanted.
How should I change the size of the dialog?

gtk

2022-09-30 20:17

1 Answers

What do you think of it like this.
(For now, check on linuxmint18)

#include<gtk/gtk.h>

int main(intargc, char*argv[])
{
    GtkWidget*dialog;

    gtk_init(&argc,&argv);

# if 0
    /* Not this way*/
    dialog=gtk_file_chooser_dialog_new("test", NULL,
             GTK_FILE_CHOOSER_ACTION_OPEN,
             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
             GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
             NULL);
    gtk_widget_set_size_request(dialog,320,240);
# else
    /* It's OK over here*/
    {
        GtkWidget* file_chooser;

        dialog=gtk_dialog_new_with_buttons("test", NULL,
                 GTK_DIALOG_MODAL,
                 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
                 NULL);
        gtk_window_set_default_size (GTK_WINDOW(dialog), 320, 240);
        file_chooser=gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_OPEN);
        gtk_widget_show(file_chooser);
        gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), file_chooser, TRUE, TRUE, 0);
    }
#endif

    g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show(dialog);

    gtk_main();
    return 0;
}

However, it seems that there is a minimum FileChooser size, so it was only about 500x380.

I looked at the gtk_file_chooser_dialog source file, but I don't know exactly, but I feel like I'm forcing you to set the default window size.


2022-09-30 20:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.