Re: Added tooltip to display details of items in TreeView



Tony Yum wrote:


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?

If you look closer at my callback you will find that it is generating that event itself :). You need that to change tooltip when moving mouse inside TreeView widget between different cells.

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

Actually, I didn't add any events to my TreeView, it had set that event by default.
In your case you should use Gdk namespace: Gdk::POINTER_MOTION_MASK.


<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.

If TreeView doesn't listen motion events in version 2.6 even when you did

<TreeWidget>.set_events( Gdk::ALL_EVENTS_MASK );

that may be GTK+ issue.




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