Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Eraser tool in QGraphicView



  • Hello, I have created a drawing tool like MS Paint follow this tutorial: https://evileg.com/en/post/84/
    Now i want to create eraser tool help me to erase the drawn line. Please help me, maybe a working example is good for me.b19d9632-14db-4985-ba41-e48164ccb58b-image.png


  • Lifetime Qt Champion

    Hi and welcome to the forums

    You can use
    QGraphicsItem *item = itemAt(event->scenePos())
    in mousePress to get the item under mouse and
    remove the lines with removeItem()

    You need a button to toggle between drawing and erasing.

    However, if you plan on making a small Raster paint app like MS paint then I'm not sure you
    are on the right path using QGraphicView.
    At least what was drawn here is a vector. tons of line segments.
    so it's not an image as it's in MS Paint. Just so you are aware that some operations
    will be harder than using a pure QPainter approach.

    I think you want more like
    https://github.com/yakzi/paint-qt


Log in to reply