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 QGraphicsPathItem from scene
Qt 6.11 is out! See what's new in the release blog

Removing QGraphicsPathItem from scene

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 1.6k 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.
  • R Offline
    R Offline
    required
    wrote on last edited by required
    #1

    Hello,
    I am creating a simple QWidget application. I'm stuck at deleting single QGraphicsPathItem object. I start from a QPainterPath object.

    QGraphicsScene *scene;
    QPainterPath foo_path;
    foo_path.moveTo(10,10);
    foo_path.lineTo(20,20);
    QGraphicsPathItem *foo_item = scene->addPath(foo_path);

    QGraphicsScene::removeItem() does not work with QGraphicsPathItem, only with QGraphicsItem.

    Is there a workaround? Thanks.

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

      This dummy example:

      #include <QApplication>
      #include <QGraphicsScene>
      #include <QGraphicsPathItem>
      #include <QPainterPath>
      
      int main(int argc, char **argv)
      {
          QApplication app(argc, argv);
          QGraphicsScene scene;
          QPainterPath path;
          QGraphicsPathItem *item = scene.addPath(path);
          scene.removeItem(item);
          return 0;
      }
      

      builds without any problem.

      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
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #2

        Hi and welcome to devnet,

        What doesn't work for you ?

        QGraphicsPathItem is a subclass of QGraphicsItem.

        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
        1
        • R Offline
          R Offline
          required
          wrote on last edited by
          #3

          Thank you for your reply.

          I'd like to delete the QGraphicsPathItem using scene->removeItem(foo_item).

          Compiler returns error "no matching function....", since removeItem only works with QGraphicsItem and there is no known conversion from 'QGraphicsPathItem*' to 'QGraphicsItem*'.

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

            This dummy example:

            #include <QApplication>
            #include <QGraphicsScene>
            #include <QGraphicsPathItem>
            #include <QPainterPath>
            
            int main(int argc, char **argv)
            {
                QApplication app(argc, argv);
                QGraphicsScene scene;
                QPainterPath path;
                QGraphicsPathItem *item = scene.addPath(path);
                scene.removeItem(item);
                return 0;
            }
            

            builds without any problem.

            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
            • R Offline
              R Offline
              required
              wrote on last edited by
              #5

              Forgot the include. Oh god.

              Thank you for your help.

              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