动态更改 gtkListStore 模型

发布于 2024-11-26 09:14:53 字数 892 浏览 2 评论 0原文

所以我终于开始了解 PyGTK 的真正工作原理,并且我正在开发一个简单的 SQLite 管理器应用程序。

为了显示查询结果,我使用了 gtk.ScrolledWindow 和 gtk.TreeView。我已经设法根据需要添加甚至更改 ListStore 对象中的值,我不能做的是更改 ListStore 对象的模型。

例如,在一个查询中,我可能会得到两列的结果:

    self.query_results = gtk.ListStore(str,str)
    self.query_results.append(["1"],["John Doe"])

在另一查询中,我可能会得到更多列:

    self.query_results = gtk.ListStore(str,str,str,str)
    self.query_results.append(["20"],["Jane"],["[email protected]"],["password"])

我知道我可以使用类似的东西

     self.query_results = gtk.ListStore(*[str]*len(columns))

但显然 gtk.ListStore 在创建后无法更改其模型,那么我将如何更新这个查询表?每次运行不同的查询时,是否需要销毁 Treeview 并重新绘制它?

谢谢,这是我在 StackOverflow 上的第一个问题,所以请原谅我没有遵循的任何错误/发布指南。

So I finally got around to understand how PyGTK really works and I'm working on a simple SQLite manager app.

To show the result of a query I'm using a gtk.ScrolledWindow with a gtk.TreeView. I've managed to add and even change the values in the ListStore object as I need, what I can't do is change the model of the ListStore object.

For example in one query I may have a result of two columns:

    self.query_results = gtk.ListStore(str,str)
    self.query_results.append(["1"],["John Doe"])

And in another one I may get more columns:

    self.query_results = gtk.ListStore(str,str,str,str)
    self.query_results.append(["20"],["Jane"],["[email protected]"],["password"])

I know I can use stuff like

     self.query_results = gtk.ListStore(*[str]*len(columns))

But aparently gtk.ListStore cannot have it's model changed after being created, so how would I update this query table? Do I need to destroy the Treeview and draw it again everytime I run a different query?

Thanks and this is my first question on StackOverflow so excuse any mistakes/posting guidelines I didn't follow.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感悟人生的甜 2024-12-03 09:14:53

您可以使用 gtk.TreeView.set_model 将新模型分配给 TreeView。因此,您可以为每组结果生成一个新模型,然后设置 TreeView 以显示该模型。

You can use gtk.TreeView.set_model to assign a new model to a TreeView. So you can generate a new model for each set of results, and then set the TreeView to show that model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文