qgraphicsscene remove item but sometime still in view
-
I use a qgraphicsscene additem a QChart and some inhert from the QChart item.I change QChart axisX and axisY range,and removeitem those items,then add new item.But sometime removeitem not working,item still in view.I cannot move it now.
And also call all of items prepareGeometryChange,not work.
So,why?I test long time,found the point is set range.if resize the view,the removed item disappear.
Qt 5.9.5 kits
-
-
This post is deleted!
-
Hi,
@choujayylyxm said in qgraphicsscene remove item but sometime still in view:
No one reply?!
No need to resort to bold fonts and such questions. A friendly ping is welcome though. This is a voluntary driven forum. People answering here do it on their own time and might not live in the same timezone as you. And it's also possible that no one has an answer for you.
In any case, you should provide a minimal compilable example that reproduces your issue.
You should also test your code against a more recent version of Qt, 5.9.5 is more than outdated. Qt 5.15 is the current LTS. Providing the platform your code runs on would also be good idea. -
Ok,I understood.Sorry for that.
Here is a simple example://click a button to switch line and run below code // a QGraphicsView scene()->addItem(m_chart); //replace a new line QLineSeries * tmp = static_cast<QLineSeries *>(m_chart->series()[0]); QList<QPointF> dataPointList; //set new axis range m_chart->axisX()->setRange(0,dataVec[dataVec.size()-1].x()); m_chart->axisY()->setRange(-qAbs(yMax)*1.2f, qAbs(yMax)*1.2f); tmp->replace(dataPointList); //delete last line a flag(circle)item in the qchart ,m_calloutsList is keep flags list for(auto& item : m_calloutsList[nDataIndex]) { //item.prepareGeomtryChange //try it not work scene()->removeItem(item); } //add current line flag item for(auto& item2 : m_calloutsList[nDataIndex]) { //item2.prepareGeomtryChange //try it not work scene()->addItem(item2); }
-
Please provide a minimal compilable example that shows the behavior.
-
@SGaist OK,I upload a minimal compilable example for github
github linkIs it okay? It base on qt example callout
-
try to After
remove the item from your qgraphicsscene
scene()->removeItem(YOURITEM_OBJECT); ui->graphicsview->viewport()->update(); ui->graphicsview->update(); ui->graphicsview->show();