Re: Added tooltip to display details of items in TreeView




Andrew E. Makeev wrote:

Tony Yum wrote:

Dear all,

I have just started using gtkmm and forgive me if the question might be a bit silly. But I don't seemed to be able to add tooltip to treeview items. i.e. I wish to display detail of the items in the treeview when I hover hover it. The tooltip object sets the text for the entire treeview, so I thought about listening to mouse motions on the treeview widget and then setting the tooltip appropriately. However as soon as I add content to the tree, the signal_motion_notify_event no longer sends signal to the slot that I connected to.


I have implemented TreeView tooltip. Works both for Gtkmm-2.2 & 2.4.

See my motion notify callback. I guess, you forgot to generate ENTER notify event to let TreeView widget think that mouse just entered, otherwise it will hide tooltip. Actually, it requires some optimization, but that is not critical issue.

Thanx for the reply.

I don't think I understand what you mean by generating an ENTER notify event? Doesn't gtkmm widget know that when a mouse is entered anyway? If not do I have to attach the signal_enter_notify_event to some slot? What slot do I have to attached it to?

I looked around the mail list and I found this:

http://mail.gnome.org/archives/gtkmm-list/2002-November/msg00165.html

which basically says use this function:

add_events(Gtk::POINTER_MOTION_MASK)

But my compiler complains that POINTER_MOTION_MASK does not exist in the Gtk namespace. I then did a grep for this in the gtkmm header files and could not find it? Maybe I am using gtkmm-2.6


<http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.html#a208>


The main problem is that no one has answered how to change tooltip position on the fly, i.e. how to display tooltip at the Cell but below TreeView.

   bool Grid::motion_notify_cb( GdkEventMotion* event )
   {
   Gtk::TreeModel::Path path;
   Gtk::TreeViewColumn *column;
   int cell_x, cell_y;

   if ( view.get_path_at_pos( (int)event->x,
                  (int)event->y,
                  path, column,
                  cell_x, cell_y ) )
   {
       Gtk::TreeModel::Row row = *viewStore->get_iter( path );
Glib::ustring tip = get_cell_tooltip( path, column->get_title() ); // this function is setting tooltip text depending on mouse position
       if( !tip.empty() )
       {
       instanceProperties.tooltips->set_tip( view, tip );
GdkEventCrossing* user_event = (GdkEventCrossing*)gdk_event_new( GDK_ENTER_NOTIFY );
       user_event->window = event->window;
       user_event->send_event = TRUE;
       user_event->subwindow = event->window;
       user_event->time = event->time;
       user_event->x = event->x;
       user_event->y = event->y;
       user_event->x_root = event->x_root;
       user_event->y_root = event->y_root;
       user_event->mode = GDK_CROSSING_NORMAL;
       user_event->detail = GDK_NOTIFY_ANCESTOR;
       user_event->focus = TRUE;
       Gdk::Event cpp_event( (GdkEvent*)user_event );
       cpp_event.put();
       }
       else
       {
       instanceProperties.tooltips->unset_tip( view );
       }
   }
   else
   {
       instanceProperties.tooltips->unset_tip( view );
   }
   return false;
   }


I'll give the above a try once I can get the tree to listen to mouse motion.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]