QGraphicsItem 如何导出为png或者svg图

发布于:2021-12-07 13:34:52

两种方式?


假设有 QGraphicsItem item;


方式一??






QPixmap pix(item->boundingRect().width(),item->boundingRect().height());


????????QPainter painter;


???????? pix.fill(Qt::transparent);//用透明色填充


????????painter.begin(&pix);


????????item->paint(&painter,nullptr,nullptr);


????????painter.end();


????????pix.save("D:/111111ww.png");


方式二


?????? QSvgGenerator generator;


????????????????generator.setFileName("D:/2223323233.svg");


????????????????generator.setSize(QSize(200, 200));


????????????????generator.setViewBox(QRect(0, 0, 200, 200));


????????????????generator.setTitle(("SVG Generator Example Drawing"));


????????????????generator.setDescription(("An SVG drawing created by the SVG Generator "


"Example provided with Qt."));


????????????//![configure SVG generator]


????????????//![begin painting]


????????????????QPainter painter;


????????????????painter.begin(&generator);


????????????//![begin painting]






???????????? //??QStyleOptionGraphicsItem??*styleItem =new QStyleOptionGraphicsItem();


????????????????item->paint(&painter,nullptr,nullptr);


????????????//![end painting]


????????????????painter.end();


相关推荐

最新更新

猜你喜欢