QGraphicsView
数百 (場合によっては数千) のデータポイントを含むズーム可能なシーンがあります。ポイントは で表されQGraphicsEllipseItem
、 にまとめられQGraphicsItemGroup
ます。ビューがズームインされている場合、データポイントを一定のサイズに保ちたい (つまり、隣接するポイント間の距離は増加しますが、サイズは同じままです)。現在、ユーザーがズームインするたびにこのコードを実行することでこれを実現しています。
#get all the QGraphicsEllipseItems that make up the QGraphicsItemGroup
children = graphics_item_group.childItems()
for c in children:
#base_size_x and base_size_y are the sizes of the
#untrasformed ellipse (on the scene) when zoom factor is 1
#New width and height are obtained from the original sizes and
#the new zoom factors (h_scale, v_scale)
new_width = base_size_x/h_scale
new_height = base_size_y/v_scale
#The top-left corner of the new rectangle for the item has to be recalculated
#when scaling in order to keep the center at a constant position
#For this, the center of the item has to be stored first
old_center_x = c.rect().center().x()
old_center_y = c.rect().center().y()
#New coordinates of the rectangle top left point are calculated
new_topleft_x = old_center_x - new_width/2.
new_topleft_y = old_center_y - new_height/2.
#Finally a new rectangle is set for the ellipse
c.setRect(new_topleft_x, new_topleft_y, new_width, new_height)
このコードは機能します。問題は、それが非常に遅いことです(補償スケーリングがなければ、ズームイン/ズームアウトは非常にスムーズに機能します)。ビューのアンチエイリアシングをオフにしようとしましたが、見栄えがかなり悪くなります。処理/再描画を高速化するために他にできることはありますか?