Signal ::expose-event is invalid for GdkWindow and GdkX11Window

微笑、不失礼 提交于 2021-02-10 18:00:41

问题


I had this following code pull from one of the tutorials on line. When I use gtk+-2.0, the following code works fine.

But when I try compile with gtk+-3.0, the code gives this error:

signal 'expose-event' is invalid for instance of type 'GtkWindow'

So I try to do the following, but still doesn't help. And it gives another error:

signal 'expose-event' is invalid for instance of type 'GdkX11Window'

gtk_widget_realize(window);
GdkWindow *gdkwin = gtk_widget_get_window(Gwindow);
int main(int argc, char *argv[])
{
  GtkWidget *window;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  g_signal_connect(window, "expose-event",
  G_CALLBACK (on_expose_event), NULL);
  g_signal_connect(window, "destroy",
  G_CALLBACK (gtk_main_quit), NULL);

  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 300, 230); 
  gtk_widget_set_app_paintable(window, TRUE);

  gtk_widget_show_all(window);

  gtk_main();
  return 0;
}

回答1:


Migrating from gtk2 to gtk3, section Changes that need to be done at the time of the switch

The GtkWidget “expose-event” signal has been replaced by a new “draw” signal, which takes a cairo_t instead of an expose event. The cairo context is being set up so that the origin at (0, 0) coincides with the upper left corner of the widget, and is properly clipped.

There is no need to connect to any signals to make your code work.



来源:https://stackoverflow.com/questions/49744185/signal-expose-event-is-invalid-for-gdkwindow-and-gdkx11window

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!