Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved qgraphicsscene remove item but sometime still in view

    General and Desktop
    3
    10
    600
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • C
      choujayylyxm last edited by choujayylyxm

      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

      1 Reply Last reply Reply Quote 0
      • C
        choujayylyxm last edited by

        someone metion :https://www.qtcentre.org/threads/28749-Qt-4-6-GraphicsView-items-remove-problem

        1 Reply Last reply Reply Quote 0
        • C
          choujayylyxm last edited by

          This post is deleted!
          SGaist 1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion @choujayylyxm last edited by

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 1
            • C
              choujayylyxm last edited by choujayylyxm

              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);
                }
              

              1.png

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                Please provide a minimal compilable example that shows the behavior.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                C 1 Reply Last reply Reply Quote 0
                • C
                  choujayylyxm last edited by choujayylyxm

                  @SGaist OK,I upload a minimal compilable example for github
                  github link

                  Is it okay? It base on qt example callout

                  1 Reply Last reply Reply Quote 0
                  • C
                    choujayylyxm @SGaist last edited by

                    @SGaist Fine,I keep working on it.

                    1 Reply Last reply Reply Quote 0
                    • SGaist
                      SGaist Lifetime Qt Champion last edited by

                      Did you try to call hide on your items before removing them from the scene ?

                      One thing: there's no need to make the QGraphicsItemObject. A simple QGraphicsRectItem is enough for your purpose.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply Reply Quote 0
                      • Ketan__Patel__0011
                        Ketan__Patel__0011 last edited by

                        try to After

                        remove the item from your qgraphicsscene

                                scene()->removeItem(YOURITEM_OBJECT);
                                ui->graphicsview->viewport()->update();
                                ui->graphicsview->update();
                                ui->graphicsview->show();
                        
                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post