gpt4 book ai didi

无法以编程方式减小 gtk 窗口的大小

转载 作者:行者123 更新时间:2023-11-30 15:20:57 25 4
gpt4 key购买 nike

我在以编程方式调整 gtk 窗口大小时似乎遇到了问题。问题是,一旦我将窗口的宽度和高度增加到 800x600,我似乎无法将其缩小回原来的大小 400x200。下面是示例代码。有人遇到过这样的问题吗?

#include <gtk/gtk.h>

static gboolean is_clicked = FALSE;

static void Child_window_resize( GtkWidget *widget,
GtkWidget *window)
{
if(!is_clicked)
{
g_print("Inside If block increase bool value %d\n",is_clicked);
gtk_widget_set_size_request(window,800,600);
is_clicked = TRUE;
}
else
{
g_print("Inside Else block decrease bool value %d\n",is_clicked);
gtk_widget_set_size_request(window,400,200);
is_clicked = FALSE;
}
}

int main(int argc, char* argv[])
{
GtkWidget *window;
GtkWidget *fixed;
GtkWidget *resizebutton;

gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window,400,200);
gtk_window_set_resizable(GTK_WINDOW(window),TRUE);
gtk_window_set_title(GTK_WINDOW(window), "Demo Resize");
gtk_window_set_decorated(GTK_WINDOW(window),FALSE);
gtk_signal_connect(GTK_OBJECT(window), "destroy",
GTK_SIGNAL_FUNC(gtk_exit), NULL);

gtk_container_set_border_width(GTK_CONTAINER(window), 10);
// creating a fixed GTK_CONTAINER
fixed = gtk_fixed_new();
gtk_container_add(GTK_CONTAINER(window),fixed);
gtk_widget_show(fixed);

resizebutton = gtk_button_new_with_label("Resize");
gtk_widget_set_size_request(resizebutton, 80, 60);
gtk_fixed_put(GTK_FIXED(fixed), resizebutton, 0, 0);

gtk_signal_connect(GTK_OBJECT(resizebutton), "clicked",
GTK_SIGNAL_FUNC(Child_window_resize), window);

gtk_widget_show(resizebutton);
gtk_widget_show(window);
gtk_main();
return 0;
}

遵守使用...

gcc -Wall -Werror -g resize.c -o resize -export-dynamic `pkg-config --cflags --libs gtk+-2.0 gthread-2.0`

非常感谢任何帮助。

最佳答案

您需要gtk_window_resize(),而不是gtk_widget_set_size_request() .

来自链接的手册:

void
gtk_window_resize (GtkWindow *window,
gint width,
gint height);

Resizes the window as if the user had done so, obeying geometry constraints. The default geometry constraint is that windows may not be smaller than their size request; to override this constraint, call gtk_widget_set_size_request() to set the window's request to a smaller value.

If gtk_window_resize() is called before showing a window for the first time, it overrides any default size set with gtk_window_set_default_size().

Windows may not be resized smaller than 1 by 1 pixels.

关于无法以编程方式减小 gtk 窗口的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29770607/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com