【发布时间】:2021-05-11 12:12:12
【问题描述】:
例如,当我有以下小部件层次结构时:
- 窗口
- 盒子
- 绘图区 1
- 绘图区 2
- 盒子
然后我在绘图区 1 上调用 queue_draw,然后绘图区 2 也被更新(绘图)。这种行为是有意的吗?出于性能原因,我是否可以阻止这种行为并且只更新绘图区 1。
编辑:添加了一个最小示例:
#!/usr/bin/env python3
import pgi
pgi.require_version('Gtk', '3.0')
from pgi.repository import Gtk, Gdk, GdkPixbuf
import cairo
class DrawingArea(Gtk.DrawingArea):
def __init__(self, id):
super().__init__()
self.id = id
self.vexpand = True
self.hexpand = True
self.connect("draw", self.on_draw)
def on_draw(self, area, context):
print ("on_draw ", self.id)
context.set_source_rgb (1, 0, 0)
context.rectangle (0,0,20,20)
context.fill ()
return False
class Window(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("Test Draw Radial Gradient")
self.set_default_size(400, 200)
self.connect("destroy", Gtk.main_quit)
self.drawingArea1 = DrawingArea (1)
self.drawingArea2 = DrawingArea (2)
box = Gtk.Box ()
box .pack_start (self.drawingArea1, True, True, 0)
box .pack_start (self.drawingArea2, True, True, 0)
button = Gtk.Button.new_with_label("Click Me")
box .pack_start (button, True, True, 0)
button.connect("clicked", self.on_click_me_clicked)
self.add(box)
def on_click_me_clicked(self, button):
print ("Button clicked")
self.drawingArea1.queue_draw()
window = Window()
window.show_all()
Gtk.main()
【问题讨论】:
-
请发布一个最小且可重现的示例,以便我们自己测试。
-
添加示例@BobMorane。