[Solved]How to show *.dxf or *.dwg files on QGraphicsScene ?
-
Hi,
In my app i am using QGraphicsScene to show an image.
I want to overlap CAD drawing onto this image so that user can visually inspect.The CAD files are in the *.dxf or *.dwg format.
Currently i am able to overlap *.png image on my image as
@
QPixmap pixx("C:/Users/Public/Pictures/Sample Pictures/tulips.jpg");
scene->addPixmap(pixx);
@My question is,
How to add cad drawings on scene? OR
Is there any other way to do this? -
Hi,
Qt doesnot support the above format. Check "supported formats":http://qt-project.org/doc/qt-5/QPixmap.html#reading-and-writing-image-files
You will need to render the above drawings to Qt supported image formats externally. -
-
[quote author="ashokb" date="1410680851"]So it means i cannot use .dxf/.dwg directly with QPixmap, QGraphicsScene.
Is there any way in qt with which i can convert these formats to supported formats ?
OR
Any way other than QPixmap, QGraphicsScene to overlap CAD drawing on image and show on GUI ?[/quote]You need to write your own parser for those file formats, or use an external library if available.
Regarding your second question: no, there is no class in Qt that understands CAD files.
-
Hi,
If you're dealing with CAD data, I guess we speak about 3D data, are'nt we? Anyway, QPixmap -- and other image classes in Qt -- are designed for bitmaps, not vector graphics. Qt only supports SVG format for vector graphics. You can take a look at the sources of the corresponding classes -- starting with "QGraphicsSvgItem":http://qt-project.org/doc/qt-5/qgraphicssvgitem.html -- to see how you can add dxf or dwg support, but I guess it will be about sub-classing QGraphicsItem and reimplement "paint()":http://qt-project.org/doc/qt-5/qgraphicsitem.html#paint. Using the QPainter passed as argument, you will be able to draw the primitives of your file -- you will have to implement a parser to load it.
-
Just for the record: The developers of "QCAD":http://www.qcad.org/ (which is written in Qt) have published their dxf library "dxflib":http://www.ribbonsoft.com/en/what-is-dxflib under the GPL.
-
Just for the record: The developers of "QCAD":http://www.qcad.org/ (which is written in Qt) have published their dxf library "dxflib":http://www.ribbonsoft.com/en/what-is-dxflib under the GPL.