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

标签 python treeview gtk3 scrolledwindow

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

我正在编写一个触摸屏信息亭应用程序,该应用程序具有向上和向下按钮以在 TreeView 中移动选择。

It doesn't it doesn't scroll down the scrolledwindow when the selection goes off the screen.

我想解决这个问题是按下向下按钮让选择向下移动一个(因为它已经这样做了)然后让滚动窗口滚动到 TreeView 上的选择但我无法弄清楚如何.

我正在使用 Gtk3

谁能给我一些想法?

最佳答案

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

不要使用“add_with_viewport”将 TreeView 添加到滚动窗口。参见 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()

关于Python:如何让 Gtk.scrolledwindow 滚动到 Gtk.Treeview 中的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572387/

相关文章:

python - 如何加快从 pandas.DataFrame .to_sql 的插入

python - Blobstore 上传处理程序时 Google App Engine 中的编码问题

javascript - 如何正确覆盖 Angular 树的样式?

c - 如何构建我想要的 GTK GUI 应用程序?

python - 如何理解Seaborn的热图注释格式?

python - scikit-learn 和 scipy 库之间的决定系数不同。为什么?

c++ - 类似文件夹树浏览器的 Windows 资源管理器

java - 设置 SWT.FULL SELECTION 时,SWT TreeViewer 同时展开和折叠

python - 为 python GTK3 应用程序创建安装程序

c - 客户端装饰如何与 Gnome 3.10 和 GTK 3 配合使用?