Re: [gtkmm] gtk+ 2.x TreeView tutorial

On Wednesday 14 July 2004 21:33, Vladislav Grinchenko wrote:
> Hi,
> just came across this *hidden* Gtk+ TreeView tutorial
> for anyone interested.


> BTW, anyone knows how to change drag icon of TreeView from
> default row?

His advice that using the standard GTK+ drag and drop mechanisms "is most 
likely not want you want" (and instead to use the high level 
Gtk::TreeView::set_reorderable()) is pretty wide of the mark, since you can 
only use the latter to drag within a single tree view.  The GTK+ drag and 
drop mechanisms are sophisticated and can do practically anything you want, 
and not that difficult once you have worked out how they operate.  It is the 
only way to drag between different tree views.

I am not sure what you mean by the "default row", but to change the drag icon 
for the selected row you would do it in a slot connected to the "drag begin" 
signal of the tree view.  You probably also want to end up with the icon 
positioned with respect to the pointer by analogy with what happens if you 
use Gtk::TreeView::set_reorderable().  You will probably end up with 
something like this:

void tree_view_drag_begin_slot(const Glib::RefPtr<Gdk::DragContext>& context)

  Gtk::TreeModel::iterator row_iter = 
  if (row_iter) {

// get the cell height for vertical displacement
    int x_off, y_off, cell_width, cell_height;
    Gdk::Rectangle area;
    tree_view.get_column(0)->cell_get_size(area, x_off, y_off, cell_width, 

// get the cursor position for horizontal displacement
    int x_pos, y_pos;
    tree_view.get_pointer(x_pos, y_pos);
    if (cell_height < 0) cell_height = 0;
    if (x_pos < 0) x_pos = 0;

    Glib::RefPtr<Gdk::Pixmap> pixmap = 
    Glib::RefPtr<Gdk::Colormap> colormap = 
    Glib::RefPtr<Gdk::Bitmap> bitmap;

// this sets the icon and positions it with respect to the cursor
    context->set_icon(colormap, pixmap, bitmap, x_pos, cell_height/2);


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