Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Gtk.TreeView中始终可见且粘滞的列_Python_Python 3.x_Treeview_Gtk_Pygobject - Fatal编程技术网

Python Gtk.TreeView中始终可见且粘滞的列

Python Gtk.TreeView中始终可见且粘滞的列,python,python-3.x,treeview,gtk,pygobject,Python,Python 3.x,Treeview,Gtk,Pygobject,我有一个Gtk.TreeView,其中3列嵌入Gtk.Paned中 当我调整窗口大小或在第一列中用较长的文本填充更多行时,最后两列不应消失 我想让最后两列始终可见并粘在右侧,而不会松开左侧列 单击按钮添加很长的字符串后,第一列不应增长。这种快速而肮脏的操纵屏幕截图: 应该是什么样子 但它看起来如何,但不应该 我在文档中看不到实现这一点的方法。在该示例中,Gtk.TreeView下面的代码嵌入到Gtk.scrolled窗口中,以允许垂直滚动条 #!/usr/bin/env python3 impo

我有一个Gtk.TreeView,其中3列嵌入Gtk.Paned中

当我调整窗口大小或在第一列中用较长的文本填充更多行时,最后两列不应消失

我想让最后两列始终可见并粘在右侧,而不会松开左侧列

单击按钮添加很长的字符串后,第一列不应增长。这种快速而肮脏的操纵屏幕截图:

应该是什么样子 但它看起来如何,但不应该 我在文档中看不到实现这一点的方法。在该示例中,Gtk.TreeView下面的代码嵌入到Gtk.scrolled窗口中,以允许垂直滚动条

#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import GLib

class TreeView(Gtk.TreeView):
    def __init__(self):
        # model
        self.model = Gtk.ListStore.new([str, int, int])
        for i in range(1, 6):
            self.model.append([('text {} '.format(i))*i, i*10, i])

        # view
        Gtk.TreeView.__init__(self, self.model)

        col_a = Gtk.TreeViewColumn('str',
                                   Gtk.CellRendererText(single_paragraph_mode=True),
                                   text=0)
        col_b = Gtk.TreeViewColumn('int',
                                   Gtk.CellRendererText(),
                                   text=1)
        col_c = Gtk.TreeViewColumn('int',
                                   Gtk.CellRendererText(),
                                   text=2)
        self.append_column(col_a)
        self.append_column(col_b)
        self.append_column(col_c)

        # scrollable
        self.scroll = Gtk.ScrolledWindow()
        self.scroll.add(self)
        self.scroll.set_policy(hscrollbar_policy=Gtk.PolicyType.NEVER,
                               vscrollbar_policy=Gtk.PolicyType.AUTOMATIC)

    def on_button(self, event):
        self.model.append(['long text '*20, 0, 0])

class Window(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self, title='Mein Gtk-Fenster')
        #self.set_default_size(100, 120)

        # tree & button
        self.view = TreeView()
        self.btn = Gtk.Button('add long row')
        self.btn.connect('clicked', self.view.on_button)

        # layout
        #box = Gtk.VBox()
        #box.pack_start(self.btn, False, False, 10)
        #box.pack_start(self.view.scroll, True, True, 10)
        #self.add(box)

        self.paned = Gtk.Paned.new(orientation=Gtk.Orientation.HORIZONTAL)
        self.paned.pack1(self.view.scroll)
        self.paned.pack2(self.btn)
        self.add(self.paned)

        self.connect('destroy', Gtk.main_quit)
        self.show_all()

if __name__ == '__main__':
    win = Window()
    Gtk.main()

至少需要两项更改:

要使用长字符串保持列的正常大小,请设置GTKCellRenderText的ellipsize属性。这应该是一个泛古埃利普西泽莫德

若要使两个右柱粘在末端,请通过将“展开”属性设置为True,展开第一列以占用所有剩余空间

使用以下更改创建列:

col_a = Gtk.TreeViewColumn('str',
                           Gtk.CellRendererText(single_paragraph_mode=True,
                                                ellipsize=Pango.EllipsizeMode.END),
                           text=0)
col_a.set_expand(True)

不要认为你需要单段落模式,以前从未使用过。

至少需要两个更改:

要使用长字符串保持列的正常大小,请设置GTKCellRenderText的ellipsize属性。这应该是一个泛古埃利普西泽莫德

若要使两个右柱粘在末端,请通过将“展开”属性设置为True,展开第一列以占用所有剩余空间

使用以下更改创建列:

col_a = Gtk.TreeViewColumn('str',
                           Gtk.CellRendererText(single_paragraph_mode=True,
                                                ellipsize=Pango.EllipsizeMode.END),
                           text=0)
col_a.set_expand(True)

不要认为你需要单段落模式,以前从未使用过。

除了@RandomUser提供的答案外,你还可以使用固定大小的列。例如:

col_a.set_fixed_width(150)
添加set_expand将提供不同的操作:

col_a.set_expand(True)

除了@RandomUser提供的答案外,还可以使用固定大小的列。例如:

col_a.set_fixed_width(150)
添加set_expand将提供不同的操作:

col_a.set_expand(True)