gpt4 book ai didi

c - GtkButton 被 GtkDrawingArea 覆盖

转载 作者:行者123 更新时间:2023-11-30 17:50:20 26 4
gpt4 key购买 nike

我试图在 C 语言的 GtkDrawingArea 上放置一个按钮(GUI 是从一个空地文件生成的)。在 Glade 中,我将 GtkDrawingArea 和 GtkButton 放入 GtkFixed 容器中。我可以单击按钮应该所在的位置,并且按钮“clicked”事件处理程序被成功调用,但按钮隐藏在 GtkDrawingArea 后面。在绘图区域的“expose-event”处理程序中,我有这个:

gboolean on_drawArea_expose_event(GtkWidget *widget, GdkEventExpose *expose, gpointer data)
{
// draw on drawingArea
gdk_window_restack( button->window, widget->window, TRUE);
return FALSE;
}

我收到以下错误:

gdk_window_restack: assertion 'gdk_window_is_toplevel (GDK_WINDOW_OBJECT (sibling)' failed

我尝试过:

gdk_window_raise( button->window);

除了重新堆叠之外,它没有抛出任何错误,但也不起作用。
有任何想法吗?提前致谢,

最佳答案

所以我最终在 DrawingArea 中手动绘制按钮,位置与 GtkButton 小部件所在的位置相同。

 {
// within expose event handler
// draw desired image onto GdkPixmap
// code to draw pix map goes here
// check to see if GtkButton exists
if( button != NULL )
{
GdkGC *buttonGC = gdk_gc_new( myPixmap );
PangoLayout *buttonLayout = gtk_widget_create_pango_layout( button, "press me");
gdk_draw_layout( myPixmap, buttonGC, button->allocation.x, button->allocation.y, buttonLayout);
}

gdk_draw_drawable ( myparameters, ...);
// clean up variables
return;
}

关于c - GtkButton 被 GtkDrawingArea 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17328993/

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