简体   繁体   English

Python:如何让Gtk.scrolledwindow滚动到Gtk.Treeview中的选择

[英]Python: How do I get Gtk.scrolledwindow to scroll to a selection in Gtk.Treeview

How do I get Gtk.scrolledwindow to scroll to a selection in Gtk.Treeview. 如何让Gtk.scrolledwindow滚动到Gtk.Treeview中的选择。

I am writing a touch screen kiosk app that has up and down button to move a selection in a treeview. 我正在编写一个触摸屏自助服务终端应用程序,它具有向上和向下按钮以在树视图中移动选择。

It doesn't it doesn't scroll down the scrolledwindow when the selection goes off the screen. 当选择离开屏幕时,它不会向下滚动滚动窗口。

My idea to get around this is when the down button is pressed for the selection to move down one (as it already does) and then for the scrolledwindow to scroll to the selection on treeview but I'm unable to work out how. 我想解决这个问题的方法是按下向下按钮以使选择向下移动(就像它已经做的那样),然后滚动窗口滚动到树视图上的选择,但我无法弄清楚如何。

I'm using Gtk3 我正在使用Gtk3

Can anyone give me any ideas? 谁能给我任何想法?

在所选路径上移动选择调用gtk_tree_view_scroll_to_cell之后

See: http://lazka.github.io/pgi-docs/Gtk-3.0/classes/TreeView.html#Gtk.TreeView.scroll_to_cell 请参阅: http//lazka.github.io/pgi-docs/Gtk-3.0/classes/TreeView.html#Gtk.TreeView.scroll_to_cell

Do not add you treeview to the scrolled window with "add_with_viewport". 不要使用“add_with_viewport”将树视图添加到滚动窗口。 See http://mailman.daa.com.au/cgi-bin/pipermail/pygtk/2009-January/016440.html http://mailman.daa.com.au/cgi-bin/pipermail/pygtk/2009-January/016440.html

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

class MyWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Auto Scroll")
        self.set_size_request(400, 200)

        self.liststore = Gtk.ListStore(str, str)
        for n in range(40):
            self.liststore.append(["Info", "http://lazka.github.io/pgi-docs/Gtk-3.0/classes/TreeView.html"])
        treeview = Gtk.TreeView(model=self.liststore)
        for n, name in enumerate(["Name", "Link"]):
            renderer_text = Gtk.CellRendererText()
            column_text = Gtk.TreeViewColumn("Text", renderer_text, text=n)
            treeview.append_column(column_text)
        scrolled_window = Gtk.ScrolledWindow()
        self.add(scrolled_window)
        scrolled_window.add(treeview)

    def main(self):
        Gtk.main

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM