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

QGraphicsSvgItem is not recognizing the files with the svg images



  • Hi,
    here is the class that i'm having problems with

    DiagramItem::DiagramItem(DiagramType diagramType, QMenu *contextMenu,
                 QGraphicsItem *parent)
        : QGraphicsSvgItem(parent)
    {
    
        myDiagramType = diagramType;
        myContextMenu = contextMenu;
    
        switch (myDiagramType) {
            case StartEnd:{
    
    
                item = new QSvgRenderer(QLatin1String("C:/Users/Lukas/Desktop/simulight_v2/images/trafosvg"));
                //this is the path for the svg image that i want to use
                break;
        }
        case Gerador:{
                item = new QSvgRenderer(QLatin1String("C:/Users/Lukas/Desktop/simulight_v2/images/geradorsvg"));
    
                break;
    ...
    }// here the switch ends
        setSharedRenderer(item);
        setFlag(QGraphicsItem::ItemIsMovable, true);
        setFlag(QGraphicsItem::ItemIsSelectable, true);
        setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
    }
    

    the problem is that qt says it cannot open these files because they were not found, how can i fix it?


  • Lifetime Qt Champion

    Hi,

    Aren't you missing the file extension ?
    Or a dot before the svg at the end of the filename ?


Log in to reply