设置对话框不可调整大小或创建另一个gtk窗口 [英] set dialog not resizable or create another gtk window
问题描述
我有一个gtk_window,它包含4个按钮。
其中一个按钮将打开一个文件选择对话框(另一个功能),当文件被选中时将显示一个对话框,其中包含3个gtk_entry (这个函数)。
$ b $ pre $ static void function_with_3_gtk_entry(gchar * message,gpointer mainwin){
GtkWidget *对话框,*标签,* content_area,* entry1,* entry2,* entry3;
创建窗口小部件* /
dialog = gtk_dialog_new_with_buttons(Nome File,mainwin,GTK_DIALOG_DESTROY_WITH_PARENT,GTK_STOCK_OK,GTK_RESPONSE_NONE,NULL);
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
entry1 = gtk_entry_new();
entry2 = gtk_entry_new();
entry3 = gtk_entry_new();
gtk_widget_set_size_request(dialog,250,200);
$ b $ * *确保当用户响应时对话框被销毁* /
g_signal_connect_swapped(对话框,响应,G_CALLBACK(gtk_widget_destroy),对话框);
/ *添加标签,并显示我们添加到对话框中的所有内容* /
gtk_container_add(GTK_CONTAINER(content_area),entry1);
gtk_container_add(GTK_CONTAINER(content_area),entry2);
gtk_container_add(GTK_CONTAINER(content_area),entry3);
gtk_widget_show_all(dialog);
}
我的问题是:
- 我可以使用另一个gtk_window代替gtk_dialog吗?
- 如何设置对话框不可调整大小?
下面的代码片段有两个功能: b $ b
-
create_dialog()会创建一个对话框,根据要求不能调整大小。 create_window )根据请求在函数内创建一个窗口。
希望这有帮助。
#include< gtk / gtk.h>
/ *创建一个对话框,用户不能调整大小。 * /
void create_dialog(GtkWidget *按钮,gpointer窗口){
GtkWidget *对话框,*标签,* content_area;
/ *对话框内容的新标签* /
label = gtk_label_new(This is a dialog!);
$ b $ / *用'OK'按钮创建一个新的对话框* /
dialog = gtk_dialog_new_with_buttons(这是一个对话框,不应该|不可以)调整大小! ,窗口,GTK_DIALOG_DESTROY_WITH_PARENT,GTK_STOCK_OK,GTK_RESPONSE_NONE,NULL);
/ *将标签添加到对话框* /
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_container_add(GTK_CONTAINER(content_area),label);
$ b $ * /正确销毁对话框* /
g_signal_connect(对话框,响应,G_CALLBACK(gtk_widget_destroy),对话框);
/ *将对话框设置为不调整大小。 * /
gtk_window_set_resizable(GTK_WINDOW(dialog),FALSE);
gtk_widget_show_all(dialog);
}
/ *在一个函数中创建一个窗口! * /
void create_window(GtkWidget * button,gpointer window){
GtkWidget * new_window,* label;
/ *对话框内容的新标签* /
label = gtk_label_new(这是一个窗口,在一个函数中创建!);
/ *创建新窗口* /
new_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
*将标签添加到窗口* /
gtk_container_add(GTK_CONTAINER(new_window),label);
gtk_widget_show_all(new_window);
钻孔实现位* /
gint main(gint argc,char ** argv){
/ *初始化GTK + * /
gtk_init(& argc,& argv);
GtkWidget * main_win,* dialog_button,* window_button,* button_container;
/ *创建一个按钮,每个功能一个。 * /
dialog_button = gtk_button_new_with_label(Create dialog!);
window_button = gtk_button_new_with_label(Create window!);
/ *将按钮组装到一个盒子中。 * /
button_container = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5);
gtk_box_pack_start(GTK_BOX(button_container),dialog_button,FALSE,FALSE,0);
gtk_box_pack_start(GTK_BOX(button_container),window_button,FALSE,FALSE,0);
$ b $ *连接信号到按钮回调函数* /
g_signal_connect(dialog_button,clicked,G_CALLBACK(create_dialog),main_win);
g_signal_connect(window_button,clicked,G_CALLBACK(create_window),main_win);
*创建一个新窗口,显示它并运行GTK + * /
main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(main_win,destroy,G_CALLBACK(gtk_main_quit),NULL);
gtk_container_add(GTK_CONTAINER(main_win),button_container);
gtk_widget_show_all(main_win);
gtk_main();
返回0;
}
I have a gtk_window which contain 4 buttons.
One of these buttons will open a file selection dialog (another function) which - when the file has been choosed - will show up a dialog with 3 gtk_entry (this function).
static void function_with_3_gtk_entry (gchar *message, gpointer mainwin){
GtkWidget *dialog, *label, *content_area, *entry1, *entry2, *entry3;
/* Create the widgets */
dialog = gtk_dialog_new_with_buttons ("Nome File", mainwin, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL);
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
entry1 = gtk_entry_new();
entry2 = gtk_entry_new();
entry3 = gtk_entry_new();
gtk_widget_set_size_request(dialog, 250, 200);
/* Ensure that the dialog box is destroyed when the user responds */
g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog);
/* Add the label, and show everything we've added to the dialog */
gtk_container_add (GTK_CONTAINER (content_area), entry1);
gtk_container_add (GTK_CONTAINER (content_area), entry2);
gtk_container_add (GTK_CONTAINER (content_area), entry3);
gtk_widget_show_all (dialog);
}
My questions are:
- can i use another gtk_window into this function instead of a gtk_dialog?
- how can i set the dialog not resizable?
The code snippet below has two functions:
create_dialog() creates a dialog which cannot be resized, as requested.
create_window() creates a window, within a function, as requested.
Hope this helps.
#include <gtk/gtk.h>
/* Create a dialog, which cannot be resized by the user. */
void create_dialog(GtkWidget *button, gpointer window) {
GtkWidget *dialog, *label, *content_area;
/* New label for dialog content */
label = gtk_label_new("This is a dialog!");
/* Make a new dialog with an 'OK' button */
dialog = gtk_dialog_new_with_buttons("This is a dialog, which (shouldn't | can't) be resized!", window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL);
/* Add label to dialog */
content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
gtk_container_add(GTK_CONTAINER(content_area), label);
/* Destroy dialog properly */
g_signal_connect(dialog, "response", G_CALLBACK(gtk_widget_destroy), dialog);
/* Set dialog to not resize. */
gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
gtk_widget_show_all(dialog);
}
/* Create a window, while in a function! */
void create_window(GtkWidget *button, gpointer window) {
GtkWidget *new_window, *label;
/*New label for dialog content */
label = gtk_label_new("This is a window, created in a function!");
/* Create new window */
new_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
/* Add label to window */
gtk_container_add(GTK_CONTAINER(new_window), label);
gtk_widget_show_all(new_window);
}
/* Boring implementation bits */
gint main(gint argc, char **argv) {
/* Initialise GTK+ */
gtk_init(&argc, &argv);
GtkWidget *main_win, *dialog_button, *window_button, *button_container;
/* Create a button, one for each function. */
dialog_button = gtk_button_new_with_label("Create dialog!");
window_button = gtk_button_new_with_label("Create window!");
/* Pack buttons into a box. */
button_container = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_pack_start(GTK_BOX(button_container), dialog_button, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(button_container), window_button, FALSE, FALSE, 0);
/* Connect signals to button callback functions */
g_signal_connect(dialog_button, "clicked", G_CALLBACK(create_dialog), main_win);
g_signal_connect(window_button, "clicked", G_CALLBACK(create_window), main_win);
/* Create a new window, show it, and run GTK+ */
main_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(main_win, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_add(GTK_CONTAINER(main_win), button_container);
gtk_widget_show_all(main_win);
gtk_main();
return 0;
}
这篇关于设置对话框不可调整大小或创建另一个gtk窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!