gtk treeview:将图像按钮放在行上

发布于 2024-10-16 09:33:13 字数 205 浏览 7 评论 0原文

对于树视图中的每一行,我想要 4 个彼此相邻的图像按钮。它们就像单选按钮一样,一次只能激活一个。每个按钮都有一个“开”和“关”图像。

我该怎么做?我弄清楚了如何将图像放在那里,以及如何放置切换按钮,但这似乎需要更多的努力,因为没有预构建的单元渲染器可以完成我想要的操作。

基本上解决我的问题的是弄清楚如何使 gtk.treeview 中的图像可点击。有什么想法吗?

For each row in my treeview, I want 4 image buttons next to each other. They will act like radio buttons, with only one being activateable at a time. Each button has an 'on' and 'off' image.

How do I do this? I figured out how to put images there, and how to put togglebuttons, but this seems to require some more effort as there is no pre-built cellrenderer that does what I want.

Basically what'd solve my problem is figuring out how to make an image in a gtk.treeview clickable. any ideas?

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

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

发布评论

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

评论(3

迷荒 2024-10-23 09:33:13

这是一个没有 kiwi 要求的简短版本。

class CellRendererClickablePixbuf(gtk.CellRendererPixbuf):

    __gsignals__ = {'clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                                (gobject.TYPE_STRING,))
                   }

    def __init__(self):
        gtk.CellRendererPixbuf.__init__(self)
        self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)

    def do_activate(self, event, widget, path, background_area, cell_area,
                    flags):
        self.emit('clicked', path)

Here is a short version without kiwi requirement.

class CellRendererClickablePixbuf(gtk.CellRendererPixbuf):

    __gsignals__ = {'clicked': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE,
                                (gobject.TYPE_STRING,))
                   }

    def __init__(self):
        gtk.CellRendererPixbuf.__init__(self)
        self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)

    def do_activate(self, event, widget, path, background_area, cell_area,
                    flags):
        self.emit('clicked', path)
他是夢罘是命 2024-10-23 09:33:13

看看这个'http://www.daa.com.au/pipermail/pygtk/2010-March/ 018355.html'。它向您展示了如何使 gtk.CellRendererPixbuf 可激活,并能够连接到单击事件信号。

cell = CellRendererPixbufXt()
cell.connect('clicked', func)

更新

正如这个答案所指出的,或者给出的参考并不像广告中那样工作。它缺少 do_activate 方法,该方法需要发出单击信号。一旦完成,cell.connect 就可以工作了。

抱歉,如果这个答案误导了任何人。

Have a look at this 'http://www.daa.com.au/pipermail/pygtk/2010-March/018355.html'. It shows you how to make a gtk.CellRendererPixbuf activatable, and able to connect to a click event signal.

cell = CellRendererPixbufXt()
cell.connect('clicked', func)

Update

As pointed out this answer, or the reference given doesn't work as advertised. It's missing the do_activate method, which needs to emit the clicked signal. Once it's done that, then the cell.connect will work.

Sorry if this answer mislead anyone.

絕版丫頭 2024-10-23 09:33:13

这对我有用:

class CellRendererClickablePixbuf(gtk.CellRendererPixbuf):
    gsignal('clicked', str)
    def __init__(self):
        gtk.CellRendererPixbuf.__init__(self)
        self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)
    def do_activate(self, event, widget, path, background_area, cell_area, flags):
        self.emit('clicked', path)

Here is what worked for me:

class CellRendererClickablePixbuf(gtk.CellRendererPixbuf):
    gsignal('clicked', str)
    def __init__(self):
        gtk.CellRendererPixbuf.__init__(self)
        self.set_property('mode', gtk.CELL_RENDERER_MODE_ACTIVATABLE)
    def do_activate(self, event, widget, path, background_area, cell_area, flags):
        self.emit('clicked', path)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文