在使用QT的QGraphicsScene类和QGraphicsSvgItem类的setElementId()函数来显示同一svg文件的不同图层,图层的位置都跑到画布scene的左上角也就是左对齐加上对齐,不用setElementId()函数设置图层时,显示的是svg文件的所有图层的叠加图,这时候图层的相对位置不变,分图层显示怎么让给图层保持原本的位置。以下是svg文件内容格式如下:
<g id=[color=rgb(0, 153, 0) !important]"layer0" slic3r:z=[color=rgb(0, 153, 0) !important]"2.5e-007">
<polygon slic3r:type="contour" points="16.752857,20.741636 64.940528,20.741636 65.604126,1...............8 16.752857,27.123678 16.752857,47.865316 0,47.865316 0,0 16.752857,0" style="fill: white" />
[color=rgb(0, 102, 102) !important]</g>
<g id=[color=rgb(0, 153, 0) !important]"layer1" slic3r:z=[color=rgb(0, 153, 0) !important]"6.5e-007">
<polygon slic3r:type="contour" points="16.752857,20.741636 64.940528,20.741636 65.323722,19.469683 65.77938,17....................731472 85.6728.434648 64.940528,27.123678 16.752857,27.123678 16.752857,47.865316 0,47.865316 0,0 16.752857,0" style="fill: white" />
[color=rgb(0, 102, 102) !important]</g>
<g id=[color=rgb(0, 153, 0) !important]"layer2" slic3r:z=[color=rgb(0, 153, 0) !important]"9.5e-007">
<polygon slic3r:type="contour" points="16.752857,20.741636 64.940528,20.741636 65.113419,20.167749 65.77938,17.957208 6...........6.626274,31.549639 65.814171,29.993521 65.12059,27.715168 64.940528,27.123678 16.752857,27.123678 16.752857,47.865316 0,47.865316 0,0 16.752857,0" style="fill: white" />
[color=rgb(0, 102, 102) !important]</g>
我使用的方法是:先利用打开读取svg文件的内容,然后利用正则表达式提取svg文件中的图层id,也就是layer0,1,1这些,然后放入容器中,接着创建QGraphicsScene类对象和QGraphicsSvgItem类对象并使用其成员函数setElementId()来显示不同图层。当时各图层出现左对齐加上对齐的现象,使用boundingRect函数获取出各图层的x,y,w,h是不同的。
求解惑!!!!!
|