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

SetPixmap in custom QGraphicsPixmapItem class not working



  • Hi.
    I've come here for help on an issue that I can't solve after quite some time looking for help.
    I created a class which "derives" from a QGraphicsPixmapItem. In the constructor I want to set the pixmap from a resource file.
    @Lshape::Lshape():-QGraphicsPixmapItem(QPixmap(":/image/Lshape1"))-
    {
    setPixmap(QPixmap(":/image/Lshape1.png"));
    }@
    I've tried loading with "qrc:/..." or "://..." but there is no help. The resource file name is "image.qrc" and the prefix /Lshape. The file name is "Lshape1.png".
    In the scene I do:
    @ Lshape * lshape = new Lshape();
    lshape->setPos(100,0);
    addItem(lshape);@

    Thanks.

    EDIT: I've also tried setPixmap(QPixmap(":/Lshape/Lshape1.png"))--;



  • Try setting an alias for the pixmap. Also, post your qrc file.


Log in to reply