Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

treeview - How to delete a row from TreeFilterModel in Python GTK

I have a treeView with a ListStore to which filter has been applied. As a result, the treeview takes a TreeFilterModel so that filtering is possible.

    # Create a tree for the driver paramenter list
    # The data in the model (three strings for each row, one for each column        
    self.listmodel = Gtk.ListStore(str, str, str)

    self.driver_filter = self.listmodel.filter_new()
    self.driver_filter.set_visible_func(self.driver_filter_func)
    
    # a treeview to see the data stored in the model
    self.treeView = Gtk.TreeView(model=self.driver_filter)
    select = self.treeView.get_selection()
    select.connect("changed", self.on_tree_selection_changed)
    # for each column
    for i, column in enumerate(titles):
        # cellrenderer to render the text
        cell = Gtk.CellRendererText()
        # the text in the first column should be in boldface
        if i == 0:
            cell.props.weight_set = True
            cell.props.weight = Pango.Weight.BOLD
        # the column is created
        col = Gtk.TreeViewColumn(column, cell, text=i)
        col.set_min_width(250)

        if i == 2:
            cell.set_property("editable", True)
            cell.connect("edited", self.on_cell_edited)

        # and it is appended to the treeview
        self.treeView.append_column(col)

    
    self.treeView.set_grid_lines(3)
    ... 

When I am selecting a row, I want to be able to delete it on the click of a button. But I am not able to do so since it is a TreeFilterModel. I cannot remove the filter because that is my requirement.

Can anyone please help me and suggest how can I delete a row in the TreeFilterModel?

question from:https://stackoverflow.com/questions/66058565/how-to-delete-a-row-from-treefiltermodel-in-python-gtk

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...