需要单元格渲染器的树视图列背后的 gtk 逻辑
根据我对 GTK 的了解,如果我有一个 TreeView,我不能只使用任何我想要显示有关列的信息的小部件。对于文本,您需要一个 gtk.CellRendererText
。对于切换按钮,是 gtk.CellRendererToggle
。对于其他任何事情,似乎您都必须自己实现,从我看到的按钮示例来看,这看起来并不简单。
首先,情况是这样吗?有没有一种简单的方法来设置您想要用来显示某些文本的任何小部件?如果不是,那为什么要这样实现呢?如果我正在设计 GTK,我只会创建某种系统,其中当添加行以及某些数据模型信息更改时,将调用用户指定的回调,这将分别添加适当的小部件或更改它。
From what I understand about GTK, if I have a TreeView, I can't just use any widget I want to display information about a column. For text, you need a gtk.CellRendererText
. For toggle buttons, a gtk.CellRendererToggle
. For anything else, it seems you have to implement yourself, which, from a sample one for buttons that I saw, doesn't look straightforward.
Firstly, is this the case? Is there an easy way to set up whatever widget you want to be used to display some text? If not, then why is it implemented this way? If I were designing GTK i would just create some sort of system where when a row was added and when some data model information changes, user-specified callbacks would be called which would add the appropriate widget or change it, respectively.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编写自定义 CellRenderer(从此链接复制粘贴!) :
pyGTK 有一个很好/简单的例子 。
编写自定义的CellRenderer并不太难,难的是如何编写自定义的widget。如果您已经学会了如何编写自定义小部件,那么编写自定义 CellRenderer 就很容易了。
这种设计背后的逻辑是灵活性。 TreeViewColumn 指示 CellRenderer 应如何显示数据(来自 TreeModel),因此表示布尔类型值的 TreeViewColumn 可以显示为文本 (CellRendererText),也可以显示为复选框 (CellRendererToggle)。例如,TreeViewColumn 表示整数类型的值,可以显示为文本 (CellRendererText),也可以显示为进度条 (CellRendererProgress),也可以显示为旋转按钮 (CellRendererSpin),或者可以显示为我们想要的任何内容。想。
To write a custom CellRenderer (copy-pasted from this link!):
And there is a good/simple example for pyGTK.
Writing a custom CellRenderer is not too hard, the hardness is that how to write a custom widget. If you have learned how to write a custom widget, then writing a custom CellRenderer is easy.
The logic behind this design is flexibility. A TreeViewColumn indicates how the data (from a TreeModel) should be displayed by a CellRenderer, thus a TreeViewColumn which represents a value of boolean type, can be displayed as a text (CellRendererText) or can be displayed as a check box (CellRendererToggle). e.g. a TreeViewColumn which represents a value of integer type, can be displayed as a text (CellRendererText) or can be displayed as a progress bar (CellRendererProgress) or can be displayed as a spin button (CellRendererSpin) or can be displayed as everything that we want.