Mouse leave on a row of GtkTreeView

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Mouse leave on a row of GtkTreeView

pspgen



How can I detect when the mouse cursor leaves a GtkTreeView row ?
Note that the signal "cursor-changed" is not what I am looking for, as it
gets emitted as if it is a mouse enter (mouseover) event and I need it to
be triggered
when the mouse has just left the row. However within "cursor-changed"
signal and gtk_tree_view_get_cursor() can be used to obtain "the latest
accessed row" to know which row the mouse cursor has previously entered. So
I at least need a way to detect when the mouse cursor leaves some row.

-------------------------------------
Mail.BG: Безплатен e-mail адрес. Най-добрите характеристики на българския пазар - 30 GB пощенска кутия, 1 GB прикрепен файл, безплатен POP3, мобилна версия и други. http://mail.bg
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Mouse leave on a row of GtkTreeView

Gtk+ - Apps Dev mailing list

 
Could you use a GtkListBox? With a list box you can add a widget to the row and connect the "enter-notify-event" and "leave-notify-event" signals. There is example code for a list box at

https://blog.gtk.org/2017/06/01/drag-and-drop-in-lists-revisited/

It is drag and drop but you could change up widgets and connect different signals easy enough.


Eric

 


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: Mouse leave on a row of GtkTreeView

Gtk+ - Apps Dev mailing list
In reply to this post by pspgen

 
With a treeview you can try measuring your rows and figure out where your cursor is in your treeview. Try the following out and see if it is of any help.

Eric


/*
    With Ubuntu16.04 and GTK3.18.
    gcc -Wall tree_row1.c -o tree_row1 `pkg-config --cflags --libs gtk+-3.0`
*/
#include<gtk/gtk.h>

static GtkTreeStore* get_tree_store();
static gboolean tree_motion(GtkWidget *widget, GdkEvent *event, gpointer *data);

int main(int argc, char *argv[])
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Tree View");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkTreeStore *store=get_tree_store();

    GtkWidget *tree=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
    gtk_tree_view_set_enable_search(GTK_TREE_VIEW(tree), TRUE);
    g_object_unref(G_OBJECT(store));

    GtkCellRenderer *renderer1=gtk_cell_renderer_text_new();
    gtk_cell_renderer_set_fixed_size(renderer1, -1, 40);
    g_object_set(renderer1, "editable", FALSE, NULL);
   
    GtkTreeViewColumn *column1=gtk_tree_view_column_new_with_attributes("Index", renderer1, "text", 0, NULL);
    GtkTreeViewColumn *column2=gtk_tree_view_column_new_with_attributes("Name", renderer1, "text", 1, NULL);
    gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column1);
    gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column2);  

    GtkWidget *scroll=gtk_scrolled_window_new(NULL, NULL);
    gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
    gtk_widget_set_vexpand(scroll, TRUE);
    gtk_widget_set_hexpand(scroll, TRUE);
    gtk_container_add(GTK_CONTAINER(scroll), tree);  

    gpointer ps[]={renderer1, scroll};
    g_signal_connect(tree, "motion-notify-event", G_CALLBACK(tree_motion), ps);
   
    GtkWidget *grid=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid), 20);
    gtk_grid_attach(GTK_GRID(grid), scroll, 0, 0, 1, 1);
    gtk_container_add(GTK_CONTAINER(window), grid);
   
    gtk_widget_show_all(window);
    gtk_main();
    return 0;  
  }
static GtkTreeStore* get_tree_store()
  {
    gint i=0;
    GtkTreeStore *store=gtk_tree_store_new(2, G_TYPE_INT, G_TYPE_STRING);
       
    GtkTreeIter iter1;
    for(i=0;i<10;i++)
      {
        gchar *string1=g_strdup_printf("Name %i", i);
        gtk_tree_store_append(store, &iter1, NULL);
        gtk_tree_store_set(store, &iter1, 0, i, 1, string1, -1);
        g_free(string1);
      }
 
    return store;
  }
static gboolean tree_motion(GtkWidget *widget, GdkEvent *event, gpointer *data)
  {
    gint motion_y=event->button.y;
    GtkRequisition minimum_size;
    GtkRequisition natural_size;
    gtk_cell_renderer_get_preferred_size(GTK_CELL_RENDERER(data[0]), widget, &minimum_size, &natural_size);
    GtkAdjustment *adjustment=gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(data[1]));
    gdouble adj_h=gtk_adjustment_get_value(adjustment);

    g_print("Row %i\n", (motion_y+(gint)adj_h)/natural_size.height);
   
    return FALSE;
  }

 

 

-----Original Message-----
From: pspgen <[hidden email]>
To: cecashon <[hidden email]>
Sent: Tue, Sep 19, 2017 11:36 am
Subject: Re: Mouse leave on a row of GtkTreeView






----- Цитат от [hidden email], на 19.09.2017 в 20:38 -----


 
Could you use a GtkListBox? With a list box you can add a widget to the row and connect the "enter-notify-event" and "leave-notify-event" signals. There is example code for a list box at

https://blog.gtk.org/2017/06/01/drag-and-drop-in-lists-revisited/

It is drag and drop but you could change up widgets and connect different signals easy enough.


Eric


Can GtkListBox have columns? With sorting, search, reorder, resize etc functionality?
My whole build is based off GtkTreeView would be very hard to switch to another widget anyway..
So I rather can't use GtkListBox.











-------------------------------------
Mail.BG: Безплатен e-mail адрес. Най-добрите характеристики на българския пазар - 30 GB пощенска кутия, 1 GB прикрепен файл, безплатен POP3, мобилна версия и други.

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list