Problem Occurred when open SVG file
Qt, Svg Reader, C++
In my project which can create rectangle and oval shape like this image .I use this code to open ellipses and rectangles.Which open rectangles and oval/ellipse properly. But when I use this types which not open properly.here with I attach sample SVG file.can you give me a solution to solve this problem.
This is part of SVG file.
<g fill="#ffffff" fill-opacity="1" stroke="#00ff00" stroke-opacity="1" stroke-width="1" stroke-linecap="square" stroke-linejoin="bevel" transform="matrix(1,0,0,1,284,160)" font-family="MS Shell Dlg 2" font-size="7.8" font-weight="400" font-style="normal" > <rect x="-20" y="-10" width="100" height="100"/> <rect x="-15" y="-5" width="90" height="90"/> </g>
This is my code (from
this
article)
QDomElement rectangle = gNode.firstChildElement("rect"); if (!rectangle.isNull()){ VERectangle *rect = new VERectangle(); auto gElement = gNode.toElement(); rect->setRect(rectangle.attribute("x").toInt(), rectangle.attribute("y").toInt(), rectangle.attribute("width").toInt(), rectangle.attribute("height").toInt()); QString fill = gElement.attribute("fill", "#ffffff"); if(fill.contains("url(#gradient")){ fill.replace(QString("url(#gradient"), QString("")); fill.replace(QString(")"), QString("")); QLinearGradient g = gradientList.at(fill.toInt() - 1); auto tmpRect = rect->rect(); g.setStart(tmpRect.left() + tmpRect.width()/2,tmpRect.top()); g.setFinalStop(tmpRect.left() + tmpRect.width()/2,tmpRect.bottom()); rect->setBrush(QBrush(g)); } else { QColor fillColor(gElement.attribute("fill", "#ffffff")); fillColor.setAlphaF(gElement.attribute("fill-opacity","0").toFloat()); rect->setBrush(QBrush(fillColor)); } QColor strokeColor(gElement.attribute("stroke", "#000000")); strokeColor.setAlphaF(gElement.attribute("stroke-opacity").toFloat()); QString transString = gElement.attribute("transform"); transString.replace(QString("matrix("),QString("")); transString.replace(QString(")"),QString("")); QStringList transList = transString.split(","); QTransform trans(rect->transform()); qreal m11 = trans.m11(); // Horizontal scaling qreal m12 = trans.m12(); // Vertical shearing qreal m13 = trans.m13(); // Horizontal Projection qreal m21 = trans.m21(); // Horizontal shearing qreal m22 = trans.m22(); // vertical scaling qreal m23 = trans.m23(); // Vertical Projection qreal m31 = trans.m31(); // Horizontal Position (DX) qreal m32 = trans.m32(); // Vertical Position (DY) qreal m33 = trans.m33(); // Addtional Projection Factor m11 = transList.at(0).toFloat(); m12 = transList.at(1).toFloat(); m21 = transList.at(2).toFloat(); m22 = transList.at(3).toFloat(); m31 = transList.at(4).toFloat(); m32 = transList.at(5).toFloat(); trans.setMatrix(m11,m12,m13,m21,m22,m23,m31,m32,m33); rect->setTransform(trans); rect->setPen(QPen(strokeColor,gElement.attribute("stroke-width", "0").toInt())); graphicsList.append(rect); continue; } // for_ovel QDomElement ovel = gNode.firstChildElement("ellipse"); if (!ovel.isNull()){ ovalshape *ellipseItem = new ovalshape(); auto oElement = gNode.toElement(); ellipseItem->setRect(ovel.attribute("cx").toFloat() - ovel.attribute("rx").toFloat(), ovel.attribute("cy").toFloat() - ovel.attribute("rx").toFloat(), ovel.attribute("rx").toFloat() * 2, ovel.attribute("ry").toFloat() * 2); QString fill = oElement.attribute("fill", "#ffffff"); if(fill.contains("url(#gradient")){ fill.replace(QString("url(#gradient"), QString("")); fill.replace(QString(")"), QString("")); QLinearGradient g = gradientList.at(fill.toInt() - 1); auto tmpRect = ellipseItem->rect(); g.setStart(tmpRect.left() + tmpRect.width()/2,tmpRect.top()); g.setFinalStop(tmpRect.left() + tmpRect.width()/2,tmpRect.bottom()); ellipseItem->setBrush(QBrush(g)); } else { QColor fillColor(oElement.attribute("fill", "#ffffff")); fillColor.setAlphaF(oElement.attribute("fill-opacity","0").toFloat()); ellipseItem->setBrush(QBrush(fillColor)); } QColor strokeColor(oElement.attribute("stroke", "#000000")); strokeColor.setAlphaF(oElement.attribute("stroke-opacity").toFloat()); QString transString = oElement.attribute("transform"); transString.replace(QString("matrix("),QString("")); transString.replace(QString(")"),QString("")); QStringList transList = transString.split(","); QTransform trans(ellipseItem->transform()); qreal m11 = trans.m11(); // Horizontal scaling qreal m12 = trans.m12(); // Vertical shearing qreal m13 = trans.m13(); // Horizontal Projection qreal m21 = trans.m21(); // Horizontal shearing qreal m22 = trans.m22(); // vertical scaling qreal m23 = trans.m23(); // Vertical Projection qreal m31 = trans.m31(); // Horizontal Position (DX) qreal m32 = trans.m32(); // Vertical Position (DY) qreal m33 = trans.m33(); // Addtional Projection Factor m11 = transList.at(0).toFloat(); m12 = transList.at(1).toFloat(); m21 = transList.at(2).toFloat(); m22 = transList.at(3).toFloat(); m31 = transList.at(4).toFloat(); m32 = transList.at(5).toFloat(); trans.setMatrix(m11,m12,m13,m21,m22,m23,m31,m32,m33); ellipseItem->setTransform(trans); ellipseItem->setPen(QPen(strokeColor,oElement.attribute("stroke-width", "0").toInt())); graphicsList.append(ellipseItem); continue; }
1
252
Do you like it? Share on social networks!
- Last comments
- AKApril 1, 2025, 11:41 a.m.Добрый день. В данный момент работаю над проектом, где необходимо выводить звук из программы в определенное аудиоустройство (колонки, наушники, виртуальный кабель и т.д). Пишу на Qt5.12.12 поско…
- VPMarch 9, 2025, 4:14 p.m.Здравствуйте! Я устанавливал Qt6 из исходников а также Qt Creator по отдельности. Все компоненты, связанные с разработкой для Android, установлены. Кроме одного... Когда пытаюсь скомпилиров…
- ИМNov. 22, 2024, 9:51 p.m.Добрый вечер Евгений! Я сделал себе авторизацию аналогичную вашей, все работает, кроме возврата к предидущей странице. Редеректит всегда на главную, хотя в логах сервера вижу запросы на правильн…
- Now discuss on the forum
- fFeb. 15, 2025, 1:46 p.m.Подскажите, пожалуйста! Как данный класс можно дополнить, чтобы созданные объекты можно было перемещать мышкой по сцене?
- Не запускается компьютер (точнее работает блок , но сам монитор вообще жесть)В общем я ничего с интернета не скачивала в последнее время. На компе никаких левых пр…
- Вопрос решен. Узнать QModelIndex элемента на который мы перетаскиваем другой элемент, можно с помощью функции indexAt(event->position().toPoint()) представления QTreeViev вызываемой в переопр…
- Спасибо большое за помощь и простите за то что отнял время своей невнимательностью.