Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Removing Widget from QGRaphicsScene without delting it
Forum Updated to NodeBB v4.3 + New Features

Removing Widget from QGRaphicsScene without delting it

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicssceneremove widget
4 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • gde23G Offline
    gde23G Offline
    gde23
    wrote on last edited by gde23
    #1

    Hello,

    I have Scene where I want to draw some new items, however a Widget inside the scene should stay there.

    My function is following

    void myDrawing::calc()
    {
        // remove the item from the scene so it does not get deleted
        m_scene->removeItem(m_table_widget->graphicsProxyWidget());
        
        // this is why i call it because i want to update the items
        m_scene->clear();
        addTheNewItemsToScene();
    
        // and now put the table widget back
        QGraphicsProxyWidget* table_proxy = m_scene->addWidget(m_table_widget);
        table_proxy->setPos(10,10);
    
        m_view->update();
    }
    

    (m_table_widget (QTableWidget), m_scene (QGraphicsScene)and m_view (QGraphicsView) are created in constructor)

    However the widget is not shown in the scene when calling the function more than once. (only on the first run).
    When I replace the line by QGraphicsProxyWidget* table_proxy = m_scene->addWidget(new QTableWidegt());
    the TableWIdget is shown.
    However it always only works on the first time. So why is it not shown, when removed and added back again? Or where is the error with the adding/removing?

    EDIT: Also calling ->show() does not have any effect. The widget is also not deleted, since i can add it to some layout or set a new parent and then it appears.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Did you also try to create a new QGraphicsProxyWidgetItem by hand and add that one to your scene ?

      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
      0
      • gde23G Offline
        gde23G Offline
        gde23
        wrote on last edited by
        #3

        @SGaist Thanks. Now its working with

        QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget;
        proxy->setWidget(groupBox);
        

        and then

           m_scene->removeItem(m_table_proxy);
           m_scene->clear();
           m_scene->addItem(m_table_proxy);
        

        Is this behavior intended or should i submit a bug?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I currently don't know but since the behaviour is different, I would fill a bug. If it's intended, the documentation should reflect that.

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved