Chinaunix首页 | 论坛 | 博客
  • 博客访问: 889502
  • 博文数量: 380
  • 博客积分: 3495
  • 博客等级: 中校
  • 技术积分: 3996
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-02 09:35
文章分类

全部博文(380)

文章存档

2015年(2)

2014年(5)

2013年(9)

2012年(9)

2011年(67)

2010年(103)

2009年(182)

2008年(3)

我的朋友

分类: C/C++

2009-03-01 20:56:20

Gnome的控件基本上跟现在的GUI常用控件是相同的。
从本次开始,会依次介绍各种控件。
这次是button开始,button分成下面几种
Normal Buttons
  相关函数 
   gtk_button_new (),gtk_button_new_with_label();
   正常的按钮还可以当成一个box用,也就是当成容器用。这样我们就可以加图像,文字等,来构成复杂的按钮了。
Toggle Buttons 开关按钮
  相关函数  
GtkWidget *gtk_toggle_button_new( void );   //空白按钮
GtkWidget *gtk_toggle_button_new_with_label( const gchar *label );//文字
GtkWidget *gtk_toggle_button_new_with_mnemonic( const gchar *label );//处理_字母的
由于它总是处于两个状态中的一个,所以相应的callback函数就成了下面这个样子。
void toggle_button_callback (GtkWidget *widget, gpointer data)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
{
/* If control reaches here, the toggle button is down */

} else {

/* If control reaches here, the toggle button is up */
}
}
设定其处于何种状态的函数
void gtk_toggle_button_set_active( GtkToggleButton *toggle_button,
gboolean is_active );
得到其处于何种状态的函数
gboolean gtk_toggle_button_get_active	(GtkToggleButton *toggle_button);

Check Buttons
GtkWidget *gtk_check_button_new( void );

GtkWidget *gtk_check_button_new_with_label ( const gchar *label );

GtkWidget *gtk_check_button_new_with_mnemonic ( const gchar *label );
其它函数跟toggle按钮的是相同的。
Radio Buttons
这个通常是成群的。
GtkWidget *gtk_radio_button_new( GSList *group );

GtkWidget *gtk_radio_button_new_from_widget( GtkRadioButton *group );

GtkWidget *gtk_radio_button_new_with_label( GSList *group,
const gchar *label );

GtkWidget* gtk_radio_button_new_with_label_from_widget( GtkRadioButton *group,
const gchar *label );

GtkWidget *gtk_radio_button_new_with_mnemonic( GSList *group,
const gchar *label );

GtkWidget *gtk_radio_button_new_with_mnemonic_from_widget( GtkRadioButton *group,
const gchar *label );

不过通常是不创建一个新GSList,然后来用。
而是下面这样。
GSList *gtk_radio_button_get_group( GtkRadioButton *radio_button );
直接用第一个按钮的,而第一个通常是用NULL来代替GSList
button2 = gtk_radio_button_new_with_label(
gtk_radio_button_get_group (GTK_RADIO_BUTTON (button1)),
"button2");
还有一个更省事的,直接省GET函数
 button2 = gtk_radio_button_new_with_label_from_widget(
GTK_RADIO_BUTTON (button1),
"button2");

阅读(622) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~