GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Oct 21, 2014 7:07 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Combox in a treeview (plain C)
PostPosted: Fri Apr 25, 2014 7:33 pm 
Offline

Joined: Fri Apr 25, 2014 6:55 pm
Posts: 2
Hello all,
I am trying to use comboboxes in a treeview.

So far, i managed to create a combobox:
-by using "combo = gtk_combo_box_text_new()".
-by creating a model "combo_model" and giving it to a combobox.
Those comboboxes seems to works well and I can use them outside of the treeview.

Now, I try to create 2 renderer. The first one uses the combo_model as a model. The 2nd one uses the model from "combo":
Code:
GtkCellRenderer *renderer[2];
...
renderer[0] = gtk_cell_renderer_combo_new();
g_object_set(renderer[0],"editable",TRUE,"has-entry",FALSE,
    "model",combo_model,"text-column",0,NULL);
renderer[1] = gtk_cell_renderer_combo_new();
g_object_set(renderer[1],"editable",TRUE,"has-entry",FALSE,
    "model",gtk_combo_box_get_model(GTK_COMBO_BOX(combo)),"text-column",0,NULL);

In the treeview, the combobox don't appear but if i click in the treeview, i can see them flickering and i can select an option. Also, I don't always understand all those option of g_object. Sometimes I find one of them while reading the Gtk manual and I can understand how to use it but sometimes it doesn't make sense for me.

I can provide the whole code (60 lines) that i wrote as a sandbox.


Top
 Profile  
 
 Post subject: Re: Combox in a treeview (plain C)
PostPosted: Sun Apr 27, 2014 4:25 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
Can you post your treeview's model code?

_________________
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.


Top
 Profile  
 
 Post subject: Re: Combox in a treeview (plain C)
PostPosted: Thu May 15, 2014 7:49 pm 
Offline

Joined: Fri Apr 25, 2014 6:55 pm
Posts: 2
Hello Joel,
Thank you for your answer. I don't have a steady access to internet so my answers may be late.
I have a source file I use for my tests:
-I create 2 combobox with 2 differents ways.
-I create the main TreeView I want to have my combobox packed in.
-I create my windows. I use a Vbox because i want to try my comboboxes outside the treeview and in the treeview at the same time.
This is how the window looks like:
(Window)
combobox1 or 2 (or both...)
(TreeView)
|combobox2|combobox1|

In this example, the comboboxes wich are in the treeview are not showned and are glitching when i click on it whereas the one outside behave just fine...
Here is the code:
Code:
#include <stdlib.h>
#include <gtk/gtk.h>

int main (void) {
   GtkWidget *window;
   GtkWidget *box;
   GtkTreeStore *store,*combo_model;
   GtkWidget *tree;
   GtkCellRenderer *renderer[2];
   GtkTreeViewColumn *column[2];
   GtkWidget *combo;
   GtkTreeIter iter;
   
   gtk_init(NULL,NULL);
   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size(GTK_WINDOW(window),200,10);
   box = gtk_box_new(GTK_ORIENTATION_VERTICAL,0);

   /* first combobox */
   combo = gtk_combo_box_text_new();
   gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(combo),"1","option1");
   gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT(combo),"2","option2");
   gtk_combo_box_set_active(GTK_COMBO_BOX(combo),0);
   
   /* Second Combobox*/
   combo_model = gtk_tree_store_new(1,G_TYPE_STRING);
   gtk_tree_store_append(combo_model,&iter,NULL);
   gtk_tree_store_set(combo_model,&iter,0,"Option1",-1);
   gtk_tree_store_append(combo_model,&iter,NULL);
   gtk_tree_store_set(combo_model,&iter,0,"Option2",-1);

   /* This is the main treeview */
   store = gtk_tree_store_new(2,G_TYPE_STRING,G_TYPE_STRING);
   tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
   renderer[0] = gtk_cell_renderer_combo_new();
   g_object_set(renderer[0],"editable",TRUE,"has-entry",FALSE,"model",combo_model,"text-column",0,NULL);
   renderer[1] = gtk_cell_renderer_combo_new();
   g_object_set(renderer[1],"editable",TRUE,"has-entry",FALSE,"model",gtk_combo_box_get_model(GTK_COMBO_BOX(combo)),"text-column",0,NULL);
   
   column[0] = gtk_tree_view_column_new_with_attributes("combo mano",renderer[0],NULL);
   gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column[0]);
   column[1] = gtk_tree_view_column_new_with_attributes("combo auto",renderer[1],NULL);
   gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column[1]);
   
   gtk_tree_store_append(store,&iter,NULL);
   gtk_tree_store_append(store,&iter,NULL);
   //gtk_tree_store_set(store,&iter,0,"2",NULL);
   
   gtk_container_add(GTK_CONTAINER(window),box);
   gtk_box_pack_start(GTK_BOX(box),combo,0,0,0);
   gtk_box_pack_start(GTK_BOX(box),tree,0,0,0);
   g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
   gtk_widget_show_all(window);
   gtk_main();
   
   return 0;
}


Top
 Profile  
 
 Post subject: Re: Combox in a treeview (plain C)
PostPosted: Wed May 21, 2014 9:12 pm 
Offline
GTK+ Guru

Joined: Sun Apr 06, 2008 6:43 pm
Posts: 286
Location: Fortress of solitude
ok, you are using GTK+-3.0. You should know that some engines render the themes oddly.

If you want to "see" the arrow of the dropdown box, I tested in my pc the code and seems that using TRUE in the property "has-entry" will show it, this is your code, with some fixes:
Code:
#include <gtk/gtk.h>

int main (int argc, char *argv[]) {
   GtkWidget *window;
   GtkWidget *box;
   GtkWidget *combo;
   GtkWidget *tree;
   GtkTreeStore *tv_model;
   GtkTreeStore *combo_model;
   GtkCellRenderer *renderer;
   GtkTreeViewColumn *column;
   GtkTreeIter iter;
   
   gtk_init (&argc, &argv);
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size (GTK_WINDOW (window), 200, 10);
   box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);

   /* first combobox */
   combo = gtk_combo_box_text_new ();
   gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "1", "option1");
   gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), "2", "option2");
   gtk_combo_box_set_active (GTK_COMBO_BOX (combo),0);
   
   /* Second Combobox*/
   combo_model = gtk_tree_store_new (1, G_TYPE_STRING);
   gtk_tree_store_append (combo_model, &iter ,NULL);
   gtk_tree_store_set (combo_model ,&iter, 0, "Option1", -1);
   gtk_tree_store_append (combo_model, &iter, NULL);
   gtk_tree_store_set (combo_model, &iter, 0, "Option2", -1);

   /* This is the main treeview */
   tv_model = gtk_tree_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
   gtk_tree_store_append (tv_model, &iter, NULL);
   gtk_tree_store_set (tv_model, &iter, 0, "Click me", 1, "Click me, too", -1);
   tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (tv_model));
   g_object_unref (tv_model);
   
   /* here we add the columns */
   renderer = gtk_cell_renderer_combo_new ();
   g_object_set (renderer, "editable", TRUE, "has-entry", TRUE, "model", combo_model, "text-column", 0, NULL);
   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, "combo mano", renderer, "text", 0, NULL);
   gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree), -1, "combo auto", renderer, "text", 0, NULL);
   g_object_unref (combo_model);
   
   gtk_container_add(GTK_CONTAINER(window),box);
   gtk_box_pack_start(GTK_BOX(box),combo,0,0,0);
   gtk_box_pack_start(GTK_BOX(box),tree,0,0,0);
   g_signal_connect(window,"destroy",G_CALLBACK(gtk_main_quit),NULL);
   gtk_widget_show_all(window);
   gtk_main();
   
   return 0;
}

_________________
* PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
* Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.


Top
 Profile  
 
 Post subject: Re: Combox in a treeview (plain C)
PostPosted: Thu May 22, 2014 9:23 pm 
Offline

Joined: Tue May 06, 2014 12:25 am
Posts: 4
Did you say you were writing a sandbox application for linux? If so could you post the code for this , I've been wanting to write something like that. Thanks...


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group