简体   繁体   English

GtkDrawingArea覆盖的GtkButton

[英]GtkButton covered by GtkDrawingArea

I'm trying to place a button over a GtkDrawingArea in C (GUI is generated from a glade file). 我正在尝试在C中的GtkDrawingArea上放置一个按钮(GUI是从林间空地文件生成的)。 In Glade I placed both the GtkDrawingArea and the GtkButton into a GtkFixed container. 在Glade中,我将GtkDrawingArea和GtkButton都放入了GtkFixed容器中。 I can click where the button is supposed to be and the buttons "clicked" event handler is successfully called, but the button is hidden behind the GtkDrawingArea. 我可以单击按钮应该位于的位置,并成功调用按钮“ clicked”事件处理程序,但是该按钮隐藏在GtkDrawingArea后面。 Within the "expose-event" handler for the Drawing Area I have this: 在绘图区域的“暴露事件”处理程序中,我有以下内容:

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

I get the following error: 我收到以下错误:

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

I tried: 我试过了:

gdk_window_raise( button->window);

As well instead of restack, that didn't throw any errors but it didn't work either. 同样,它也没有引发任何错误,但没有重新堆栈,但是也没有起作用。
Any ideas? 有任何想法吗? Thanks in advance, 提前致谢,

So I ended up drawing the button manually within the DrawingArea in the same location the GtkButton widget is located. 因此,我最终在GtkButton小部件所在的相同位置的DrawingArea中手动绘制了按钮。

 {
 // 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM