GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Aug 31, 2016 4:02 pm

All times are UTC

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: gtktreeview popup or contextmenu
PostPosted: Mon Apr 09, 2007 1:45 pm 
GTK+ Guru

Joined: Thu Nov 16, 2006 5:08 am
Posts: 259
Location: INDIA
hi all
i tried this
view_popup_menu (GtkWidget *treeview, GdkEventButton *event, gpointer userdata)
GtkWidget *button;
int no=0;

topmenu = gtk_menu_new();
button = gtk_menu_item_new_with_label("one");
gtk_signal_connect(GTK_OBJECT(button), "activate",
GTK_SIGNAL_FUNC(on_oneButton_clicked ), NULL);
gtk_menu_append(GTK_MENU(topmenu), button);

button = gtk_menu_item_new_with_label("two");
gtk_signal_connect(GTK_OBJECT(button), "activate",
GTK_SIGNAL_FUNC(twobutton_clicked ), NULL);
gtk_menu_append(GTK_MENU(topmenu), button);

/* Note: event can be NULL here when called from view_onPopupMenu;
* gdk_event_get_time() accepts a NULL argument */
gtk_menu_popup(GTK_MENU(topmenu), NULL, NULL, NULL, NULL,
(event != NULL) ? event->button : 0,

void set_selected(GtkWidget *treeview, GdkEventButton *event, gpointer userdata)

/* single click with the right mouse button? */

if (event->type == GDK_BUTTON_PRESS && event->button == 3)
g_print ("Single right click on the tree view.\n");

/* optional: select row if no row is selected or only
* one other row is selected (will only do something
* if you set a tree selection mode as described later
* in the tutorial) */
if (1)
GtkTreeSelection *selection;

selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));

/* Note: gtk_tree_selection_count_selected_rows() does not
* exist in gtk+-2.0, only in gtk+ >= v2.2 ! */
if (gtk_tree_selection_count_selected_rows(selection) <= 1)
GtkTreePath *path;

/* Get tree path for row that was clicked */
if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview),
(gint) event->x,
(gint) event->y,
&path, NULL, NULL, NULL))
gtk_tree_selection_select_path(selection, path);
} /* end of optional bit */

view_popup_menu(treeview, event, userdata);

return TRUE; /* we handled this */

return FALSE; /* we did not handle this */


and signal is
gtk_signal_connect(GTK_OBJECT(view), "button_press_event",
GTK_SIGNAL_FUNC(set_selected), NULL);

here is a problem
the treeview is not selecting for leftclick.
i wanna do like this
first i wanna select an item in the treeview
if i click the mouse rightbutton popupmenu will comes.

is there any way

if you have please send me code

thank you in advance

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 2 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group