我正在使用Qt來繪製一些數據可視化。我有一些線條表示時間軸上的某些重要點,但我希望能夠從視圖中刪除這些線條,以便下方的信息更清晰可見。Qt - 在QGraphicsScene中編輯QGraphicsLineItems
我明白如何將它們從視線中移除,但問題是如何在場景視圖中查找哪些QGraphicsItem是線條,哪些不是。
我一直在使用
try {
qgraphicsitem_cast<QGraphicsLineItem>(scene->items()[i]);
} catch (...) {
}
試圖但這並不甚至編譯。我試着檢查qgraphicsitem_cast()的輸出是否爲0,但編譯器也不喜歡這樣。
這是我最當前的代碼:
void Plotter::showHideLines() {
int i;
QGraphicsLineItem l;
for (i = 0; i < scene->items().count(); i++) {
try {
qgraphicsitem_cast<QGraphicsLineItem>(scene->items()[i]);
scene->items()[i]->setVisible(!scene->items()[i]->isVisible());
} catch (...) {
}
}
}
忽略「L」,我沒有打擾嘗試別的東西之後將其刪除。
我對Qt很新,我剛剛在過去幾天裏學習它。任何人都可以幫忙嗎?
你爲什麼要嘗試刪除線?不吸引他們不容易嗎?嘗試在QGraphicsView中擦除可能比你想象的有更多的背景時被認爲更難... – Uflex
嗯,我想要讓它們可見或不可見的選項。他們需要在那裏,他們向用戶提供信息。 – Luke