Tree View Scrolling

I am trying to get a GtkTree to show all of the children if possible when the user expands the parent. This is my callback routine on the row-expanded signal. The technique I thought I would use is to first scroll the tree to the last row. Then scroll it back to the parent. This would make sure that the parent is always visible and at least at the top.

The gtk_tree_view_scroll_to_cell has an alignment boolean that seems to make the change. However, I am getting a repainting effect when no scrolling movement is necessary because everything is displayed. Does anyone have a method to do this. When I tried using both of my scroll for false on the alignment, nothing changed. The second scroll back to the parent has to be true for any scrolling to take place, but this is also what causes the screen to flash.

        GtkTreeStore* treeStore = ftw->getGtkTreeStore();
        GtkTreeModel* treeModel = GTK_TREE_MODEL(treeStore);
        GtkTreeView*  treeView  = GTK_TREE_VIEW(ftw->getGtkTreeView());

        GtkTreePath* iterPath =
                gtk_tree_model_get_path(treeModel, startIter);
        bool isRowExpanded = gtk_tree_view_row_expanded(treeView, iterPath);

        // This row should have been expanded already.
        FATAL_ERROR_IF (NOT isRowExpanded);

        bool iterHasChild = gtk_tree_model_iter_has_child(treeModel,
        if (iterHasChild)
int numChildren = gtk_tree_model_iter_n_children(treeModel, startIter);
                FATAL_ERROR_IF (numChildren <= 0);

                GtkTreeIter iter;
                bool valid =

// valid is false when numChildren is too big, or startIter has no children.
                FATAL_ERROR_IF (NOT valid);

                // Scroll to the last child to get it visible
                iterPath = gtk_tree_model_get_path(treeModel, &iter);
                                             false, // do not use align
                                             0,     // row align is ignored
                                             0);    // col align is ignored

// Now scroll to the parent where we started. The effect of this is to try // to show the last child if possible while being able to see the parent at
                // the top.
                iterPath = gtk_tree_model_get_path(treeModel, startIter);
                                             true, // use align or these 2 scrolls cancel out
                                             0,    // row align is ignored
                                             0.0); // col align is ignored

Thanks for any help.

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