scroll a tree view to sepcific row

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

scroll a tree view to sepcific row

Klaus Rudolph
Hi all,

I simply want to scroll to a specific position (row) in a tree view.

I found in the docs a method:
    void Gtk::TreeView::scroll_to_row

but I have no idea how to get the parameter "path" for my row.


I build up my model like this:
    m_refTreeModel = Gtk::ListStore::create(m_Columns);
    m_TreeView.set_model(m_refTreeModel);

and fill with:
    Gtk::TreeModel::Row row = *(m_refTreeModel->append());
    row[m_Columns.m_col_id] = 1;
    ....

And now I simply want to scroll to the 7. row and also want to set it selected.

But how can I find the "path"?

Regards
 Klaus



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: scroll a tree view to sepcific row

Daniel Boles

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: scroll a tree view to sepcific row

Daniel Boles
I meant get_path(TreeIter)

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Aw: Re: scroll a tree view to sepcific row

Klaus Rudolph
I tried it with your function, but nothing happens ( no error and no change of scroll area )
 
   
    // now move to a specific row ... did not work
    Gtk::TreeModel::Children childs = m_refTreeModel->children();
    
    int cnt=0;
    Gtk::TreeModel::Children::iterator iter = childs.begin();
    while ( iter != childs.end() )
    {
        Gtk::TreeModel::Row row2 = *iter;
        cnt++;
        if ( cnt == 7 ) break;
    }
    
    // ???
    //Gtk::TreePath p1("8:");
    Gtk::TreePath p1 = m_refTreeModel->get_path( iter );
    m_TreeView.scroll_to_row( p1, 0);
 
nothing happens :-(
 
Regards
 Klaus
 
Gesendet: Mittwoch, 16. August 2017 um 09:12 Uhr
Von: "Daniel Boles" <[hidden email]>
An: gtkmm-list <[hidden email]>
Betreff: Re: scroll a tree view to sepcific row
I meant get_path(TreeIter)
_______________________________________________ gtkmm-list mailing list [hidden email] https://mail.gnome.org/mailman/listinfo/gtkmm-list

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Re: scroll a tree view to sepcific row

Daniel Boles
You never move iter beyond children.begin().


_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Re: scroll a tree view to sepcific row

Daniel Boles
Besides, although you could add the missing increment, there's no need; if you know you have enough rows, you can just index into children using operator[].

Also, why does row2 exist? It's not used for anything.

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Aw: Re: Re: scroll a tree view to sepcific row

Klaus Rudolph
In reply to this post by Daniel Boles
Hi again,

>You never move iter beyond children.begin().
 

Yepp... iter++ fix the problem :-) THANKS!

I saw for a c code example that there is a possibility to get a path from ustring in some notation like "7:".
http://scentric.net/tutorial/sec-treemodel-rowref.html

So I also tried



    Gtk::TreePath p1("8:");
    m_TreeView.scroll_to_row( p1, 0);

compiles but did nothing. Is my syntax for the string invalid or must it be converted before?

And as shown in my now fixed first example code snippet, ist it possible to get the iterator direct from the model without manually coding the iterating loop over all the children?

Regards
 Klaus
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: scroll a tree view to sepcific row

Daniel Boles
On 16 August 2017 at 08:43, Klaus Rudolph <[hidden email]> wrote:
    Gtk::TreePath p1("8:");
    m_TreeView.scroll_to_row( p1, 0);

compiles but did nothing. Is my syntax for the string invalid or must it be converted before?

The syntax is invalid, AFAICT. The same page explains:

" Now 'Songs' is the first child (from the root) and thus its tree path is just "0". 'Videos' is the second child from the root, and its tree path is "1" "

 
And as shown in my now fixed first example code snippet, ist it possible to get the iterator direct from the model without manually coding the iterating loop over all the children?

I guess you missed my other reply:

"Besides, although you could add the missing increment, there's no need; if you know you have enough rows, you can just index into children using operator[]."

.children() returns a vector. A vector has operator[] (or even .at() if you want to enforce bounds-checking, e.g. if the index comes from uncontrollable user input)



_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Aw: Re: Re: Re: scroll a tree view to sepcific row

Klaus Rudolph
Hi Daniel,

>  I guess you missed my other reply:
 
Yes, I missed it... sorry!

> ...  and thus its tree path is just "0".

Got it to work!

Perfect! Thanks very much for your help!

Regards
 Klaus
_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Re: Re: Re: scroll a tree view to sepcific row

Daniel Boles
Great, you're welcome!

_______________________________________________
gtkmm-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtkmm-list