⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gtkfaq.txt

📁 gtk是linux一款强大的夸平台的图形化开发工具
💻 TXT
📖 第 1 页 / 共 5 页
字号:
  apply for "gchar *[]" (array of an unspecified number of pointers to  char) into "const gchar *[]" (array of an unspecified number of  pointers to const char).  The type qualifier "const" may be subject to automatic casting, but in  the array case, it is not the array itself that needs the (const)  qualified cast, but its members, thus changing the whole type.  66..  DDeevveellooppmmeenntt wwiitthh GGTTKK++:: wwiiddggeett ssppeecciiffiicc qquueessttiioonnss  66..11..  HHooww ddoo II ffiinndd oouutt aabboouutt tthhee sseelleeccttiioonn ooff aa GGttkkLLiisstt??  Get the selection something like this:       GList *sel;       sel = GTK_LIST(list)->selection;  This is how GList is defined (quoting glist.h):       typedef struct _GList GList;       struct _GList       {         gpointer data;         GList *next;         GList *prev;       };  A GList structure is just a simple structure for doubly linked lists.  there exist several g_list_*() functions to modify a linked list in  glib.h.  However the GTK_LIST(MyGtkList)->selection is maintained by  the gtk_list_*() functions and should not be modified.  The selection_mode of the GtkList determines the selection facilities  of a GtkList and therefore the contents of  GTK_LIST(AnyGtkList)->selection:  selection_mode          GTK_LIST()->selection contents  ------------------------------------------------------  GTK_SELECTION_SINGLE)   selection is either NULL                          or contains a GList* pointer                          for a single selected item.  GTK_SELECTION_BROWSE)   selection is NULL if the list                          contains no widgets, otherwise                          it contains a GList* pointer                          for one GList structure.  GTK_SELECTION_MULTIPLE) selection is NULL if no listitems                          are selected or a a GList* pointer                          for the first selected item. that                          in turn points to a GList structure                          for the second selected item and so                          on  GTK_SELECTION_EXTENDED) selection is NULL.  The data field of the GList structure GTK_LIST(MyGtkList)->selection  points to the first GtkListItem that is selected.  So if you would  like to determine which listitems are selected you should go like  this:  Upon Initialization:       {               gchar           *list_items[]={                                       "Item0",                                       "Item1",                                       "foo",                                       "last Item",                               };               guint           nlist_items=sizeof(list_items)/sizeof(list_items[0]);               GtkWidget       *list_item;               guint           i;               list=gtk_list_new();               gtk_list_set_selection_mode(GTK_LIST(list), GTK_SELECTION_MULTIPLE);               gtk_container_add(GTK_CONTAINER(AnyGtkContainer), list);               gtk_widget_show (list);               for (i = 0; i < nlist_items; i++)               {                       list_item=gtk_list_item_new_with_label(list_items[i]);                       gtk_object_set_user_data(GTK_OBJECT(list_item), (gpointer)i);                       gtk_container_add(GTK_CONTAINER(list), list_item);                       gtk_widget_show(list_item);               }       }  To get known about the selection:       {               GList   *items;               items=GTK_LIST(list)->selection;               printf("Selected Items: ");               while (items) {                       if (GTK_IS_LIST_ITEM(items->data))                               printf("%d ", (guint)                       gtk_object_get_user_data(items->data));                       items=items->next;               }               printf("\n");       }  66..22..  II ddoonn''tt wwaanntt tthhee uusseerr ooff mmyy aapppplliiccaattiioonnss ttoo eenntteerr tteexxtt iinnttoo aa  GGttkkCCoommbboo.. AAnnyy iiddeeaa??  A GtkCombo has an associated entry which can be accessed using the  following expression:             GTK_COMBO(combo_widget)->entry  If you don't want the user to be able to modify the content of this  entry, you can use the gtk_entry_set_editable() function:             void gtk_entry_set_editable(GtkEntry *entry,                                         gboolean editable);  Set the editable parameter to FALSE to disable typing into the entry.  66..33..  HHooww ddoo II ccaattcchh aa ccoommbboo bbooxx cchhaannggee??  The entry which is associated to your GtkCombo send a "changed" signal  when:  +o  some text is typed in  +o  the selection of the combo box is changed  To catch any combo box change, simply connect your signal handler with             gtk_signal_connect(GTK_COMBO(cb)->entry,                                "changed",                                GTK_SIGNAL_FUNC(my_cb_change_handler),                                NULL);  66..44..  HHooww ccaann II ddeeffiinnee aa sseeppaarraattiioonn lliinnee iinn aa mmeennuu??  See the Tutorial for information on how to create menus.  However, to  create a separation line in a menu, just insert an empty menu item:       menuitem = gtk_menu_item_new();       gtk_menu_append(GTK_MENU(menu), menuitem);       gtk_widget_show(menuitem);  66..55..  HHooww ccaann II rriigghhtt jjuussttiiffyy aa mmeennuu,, ssuucchh aass HHeellpp??  Depending on if you use the MenuFactory or not, there are two ways to  proceed.  With the MenuFactory, use something like the following:       menu_path = gtk_menu_factory_find (factory,  "<MyApp>/Help");       gtk_menu_item_right_justify(menu_path->widget);  If you do not use the MenuFactory, you should simply use:       gtk_menu_item_right_justify(my_menu_item);  66..66..  HHooww ddoo II aadddd ssoommee uunnddeerrlliinneedd aacccceelleerraattoorrss ttoo mmeennuu iitteemmss??  Damon Chaplin, the technical force behind the Glade project, provided  the following code sample (this code is an output from Glade). It  creates a small File menu item with only one child (New). The F in  File and the N in New are underlined, and the relevant accelerators  are created.         menubar1 = gtk_menu_bar_new ();         gtk_object_set_data (GTK_OBJECT (window1), "menubar1", menubar1);         gtk_widget_show (menubar1);         gtk_box_pack_start (GTK_BOX (vbox1), menubar1, FALSE, FALSE, 0);         file1 = gtk_menu_item_new_with_label ("");         tmp_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (file1)->child),                                          _("_File"));         gtk_widget_add_accelerator (file1, "activate_item", accel_group,                                     tmp_key, GDK_MOD1_MASK, 0);         gtk_object_set_data (GTK_OBJECT (window1), "file1", file1);         gtk_widget_show (file1);         gtk_container_add (GTK_CONTAINER (menubar1), file1);         file1_menu = gtk_menu_new ();         file1_menu_accels = gtk_menu_ensure_uline_accel_group (GTK_MENU (file1_menu));         gtk_object_set_data (GTK_OBJECT (window1), "file1_menu", file1_menu);         gtk_menu_item_set_submenu (GTK_MENU_ITEM (file1), file1_menu);         new1 = gtk_menu_item_new_with_label ("");         tmp_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (new1)->child),                                          _("_New"));         gtk_widget_add_accelerator (new1, "activate_item", file1_menu_accels,                                     tmp_key, 0, 0);         gtk_object_set_data (GTK_OBJECT (window1), "new1", new1);         gtk_widget_show (new1);         gtk_container_add (GTK_CONTAINER (file1_menu), new1);  66..77..  HHooww ddoo II rriigghhtt ((oorr ootthheerrwwiissee)) jjuussttiiffyy aa GGttkkLLaabbeell??  Are you sure you want to _j_u_s_t_i_f_y the labels?  The label class contains  the gtk_label_set_justify() function that is used to control the  justification of a multi-line label.  What you probably want is to set the _a_l_i_g_n_m_e_n_t of the label, ie right  align it, center it or left align it. If you want to do this, you  should use:       void gtk_misc_set_alignment     (GtkMisc *misc,                                       gfloat xalign,                                       gfloat yalign);  where the xalign and yalign values are floats in [0.00;1.00].       GtkWidget       *label;       /* horizontal : left align, vertical : top */       gtk_misc_set_alignment(GTK_MISK(label), 0.0f, 0.0f);       /* horizontal : centered, vertical : centered */       gtk_misc_set_alignment(GTK_MISK(label), 0.5f, 0.5f);       /* horizontal : right align, vertical : bottom */       gtk_misc_set_alignment(GTK_MISK(label), 1.0f, 1.0f);  66..88..  HHooww ddoo II sseett tthhee ccoolloorr aanndd ffoonntt ooff aa GGttkkLLaabbeell uussiinngg aa RReessoouurrccee  FFiillee??  The widget name path constructed for a Label consists of the widget  names of its object hierarchy as well, e.g.  window (name: humphrey)    hbox      label (name: mylabel)  The widget path your pattern needs to match would be:  humphrey.GtkHBox.mylabel  The resource file may look something like:  style "title"  {        fg[NORMAL] = {1.0, 0.0, 0.0}        font = "-adobe-helvetica-bold-r-normal--*-140-*-*-*-*-*-*"  }  widget "*mylabel" style "title"  In your program, you would also need to give a name to the Label  widget, which can be done using:    label = gtk_label_new("Some Label Text");    gtk_widget_set_name(label, "mylabel");    gtk_widget_show(label);  66..99..  HHooww ddoo II ccoonnffiigguurree TToooollttiippss iinn aa RReessoouurrccee FFiillee??  The tooltip's window is named "gtk-tooltips", GtkTooltips in itself is  not a GtkWidget (though a GtkObject) and as such is not attempted to  match any widget styles.  So, you resource file should look something like:  style "postie"  {        bg[NORMAL] = {1.0, 1.0, 0.0}  }  widget "gtk-tooltips*" style "postie"  66..1100..  HHooww ddoo II uussee hhoorriizzoonnttaall ssccrroollllbbaarrss wwiitthh aa GGttkkTTeexxtt wwiiddggeett??  The short answer is that you can't. The current version of the GtkText  widget does not support horizontal scrolling. There is an intention to  completely rewrite the GtkText widget, at which time this limitation  will be removed.  66..1111..  II ccaann''tt aadddd mmoorree tthhaann ((ssoommeetthhiinngg lliikkee)) 22000000 cchhaarrss iinn aa GGttkkEEnn--  ttrryy.. WWhhaatt''ss wwrroonngg??  There is now a known problem in the GtkEntry widget. In the  gtk_entry_insert_text() function, the following lines limit the number  of chars in the entry to 2047.         /* The algorithms here will work as long as, the text size (a          * multiple of 2), fits into a guint16 but we specify a shorter          * maximum length so that if the user pastes a very long text, there          * is not a long hang from the slow X_LOCALE functions.  */         if (entry->text_max_length == 0)           max_length = 2047;         else           max_length = MIN (2047, entry->text_max_length);  66..1122..  HHooww ddoo II cchhaannggee tthhee ffoonntt ooff aa GGttkkTTeexxtt wwiiddggeett??  There are a couple of ways of doing this. As GTK+ allows the  appearance of applications to be changed at run time using resources  you can use something like the following in the appropriate file:       style "text"       {         font = "-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-*-*"       }  Another way to do this is to load a font within your program, and then  use this in the functions for adding text to the text widget. You can  load a font using, for example:         GdkFont *font;         font = gdk_font_load("-adobe-helvetica-medium-r-normal--*-140-*-*-*-*-*-*");  66..1133..  HHooww ddoo II sseett tthhee ccuurrssoorr ppoossiittiioonn iinn aa GGttkkTTeexxtt oobbjjeecctt??  Notic

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -