使用libglade在GTK+中载入Glade设计的图形界面
2007-08-11 11:58
357 查看
Glade是GTK+的界面辅助设计工具,可以通过拖放控件的方式快速设计出用户界面。
建立界面:
首先在Glade中建立一个窗口名为main,然后在上面放置一个按钮GtkButton名为button1,并且在“信号”标签中选中“clicked”事件,为此事件指定一个回调函数名称,例如回调函数是 void on_button_clicked(GtkWidget *widget),则只需在“clicked”事件的回调函数名称处填on_button_clicked。最后保存界面设计文件为 myWindow.glade。
代码中调用:
首先需要引用libglade的头文件:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <glade/glade.h>
如下代码便可:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GladeXML *xml = glade_xml_new("myWindow.glade", NULL, NULL); //载入并新建整个界面
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//自动连接Glade设置的回调关系 (刚才在Glade中我们设置了button1的clicked事件回调函数为on_button_clicked)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
glade_xml_signal_autoconnect(xml);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//获取主窗体
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GtkWidget *mainWindow = glade_xml_get_widget(xml,"main");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//设置窗体标题(其实在Glade中就可以设置)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
gtk_window_set_title(GTK_WINDOW(mainWindow),"My Test Window");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//获取按钮
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GtkWidget *button = glade_xml_get_widget(xml,"button1");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
on_button_clicked代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void on_button_clicked(GtkWidget *widget)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g_print("button1 clicked /n");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
最后在gcc链接的时候必须加上-rdynamic参数,这样才能使
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
glade_xml_signal_autoconnect(xml); 调用找到对应的回调函数。
建立界面:
首先在Glade中建立一个窗口名为main,然后在上面放置一个按钮GtkButton名为button1,并且在“信号”标签中选中“clicked”事件,为此事件指定一个回调函数名称,例如回调函数是 void on_button_clicked(GtkWidget *widget),则只需在“clicked”事件的回调函数名称处填on_button_clicked。最后保存界面设计文件为 myWindow.glade。
代码中调用:
首先需要引用libglade的头文件:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include <glade/glade.h>
如下代码便可:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GladeXML *xml = glade_xml_new("myWindow.glade", NULL, NULL); //载入并新建整个界面
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//自动连接Glade设置的回调关系 (刚才在Glade中我们设置了button1的clicked事件回调函数为on_button_clicked)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
glade_xml_signal_autoconnect(xml);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//获取主窗体
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GtkWidget *mainWindow = glade_xml_get_widget(xml,"main");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//设置窗体标题(其实在Glade中就可以设置)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
gtk_window_set_title(GTK_WINDOW(mainWindow),"My Test Window");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
//获取按钮
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
GtkWidget *button = glade_xml_get_widget(xml,"button1");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
on_button_clicked代码:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void on_button_clicked(GtkWidget *widget)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g_print("button1 clicked /n");
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
最后在gcc链接的时候必须加上-rdynamic参数,这样才能使
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
glade_xml_signal_autoconnect(xml); 调用找到对应的回调函数。
相关文章推荐
- 学习使用GTK+ 3.使用GtkBuilder、界面设计器Glade和其他GTK+组件
- 界面原型设计工具使用系列(一)-Frame Box
- SilverlightLoader使用托管代码创建自定义载入界面及动态加载XAP
- python使用easygui写图形界面程序
- 使用html设计界面
- Linux 初级班(A) – 1. Linux图形界面使用
- Win10使用附件中的远程桌面连接Ubuntu 16.04图形界面(xrdp方法)
- 分享一个使用MUIEditor设计的仿360安全卫士的界面
- Qt Creator 之mplayer播放器图形界面设计
- 使用图形界面调试arm程序: insight + gdb
- AgileEAS.NET5.0-界面设计器-使用说明书(上)
- 使用BootStrap和Metroui设计的metro风格微网站或手机app界面
- Ubuntu下使用root用户登录图形界面
- 使用设计器创建带有 ListView 和 TreeView 控件的资源管理器样式的界面 [无限级treeview]
- Ubuntu 13.04设置root用户登录图形界面与在Ubuntu 12.10中使用root进行登录方法
- C#界面设计之通用对话框的使用
- C语言的窗口式图形界面设计——自带汉字环境的应用软件编程http://bbs.51cto.com/thread-63947-1-1.html
- Android手机UI设计---”知乎“界面外观模仿篇(一)---使用Fragment实现底部导航以及嵌套
- Mac OS下使用X11访问远程Unix 主机图形界面
- centos 6.5下使用中文输入法,切换图形界面和命令行