Re: Added tooltip to display details of items in TreeView



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.

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;
   }




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