我在 c /Qt 中有一個簡單的節點圖形編輯器,它使用 QGraphicsView/QGraphicsScene 來繪制圖形,我遇到了一個奇怪的問題,即在呼叫 scene.removeItem(Item) 后 QGraphicsItems 有時會在場景中停留片刻。我將這些專案從場景中洗掉后立即洗掉,因此會導致段錯誤。當我將洗掉注釋掉時,我可以看到專案的一部分(而不是全部)在完全消失之前有一秒鐘的字面意義。
這是我的代碼。它是一個在連接被洗掉時被 a 呼叫的插槽。
void GraphScene::connectionRemoved(QUuid uuid)
{
//Connections and nodes are stored in QMaps to retrieve them by uuid
ConnectionGraphicsItem *connectionItem = connections.value(uuid);
if (connectionItem == nullptr) return;
removeItem(connectionItem); //Delayed
//delete connectionItem;
qDebug() << "con removed" << uuid;
}
在從場景中移除專案之前,我嘗試呼叫 prepareGeometryChange() 并且它沒有修復它。將 QGraphicsView 更新模式設定為 FullViewportUpdate 也無濟于事。
uj5u.com熱心網友回復:
我已經解決了這個問題。Qt 檔案
void QGraphicsItem::prepareGeometryChange()
宣告您需要在更改專案的邊界矩形之前呼叫此方法,以便圖形場景更新其索引。我沒有這樣做。因此,當我在調整連接以匹配節點埠的代碼之前添加它時,問題就消失了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491175.html
