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; }
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
AD
- Akiv Doros
- Nov. 12, 2024, 1:58 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:50points,
- Rating points-4
m
- molni99
- Oct. 26, 2024, 11:37 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:80points,
- Rating points4
m
- molni99
- Oct. 26, 2024, 11:29 a.m.
C ++ - Test 004. Pointers, Arrays and Loops
- Result:20points,
- Rating points-10
Last comments
Evgenii LegotckoiNov. 1, 2024, 12:37 a.m.
Fb3 file reader on Qt Creator Подскажите как это запустить? Я не шарю в программировании и кодинге. Скачал и установаил Qt, но куча ошибок выдается и не запустить. А очень надо fb3 переконвертировать в html
ИМ
Django - Lesson 064. How to write a Python Markdown extension Приветствую Евгений! У меня вопрос. Можно ли вставлять свои классы в разметку редактора markdown? Допустим имея стандартную разметку: <ul> <li></li> <li></l…
Игорь МаксимовOct. 5, 2024, 5:51 p.m.
QML - Lesson 016. SQLite database and the working with it in QML Qt Здравствуйте, возникает такая проблема (я новичок): ApplicationWindow неизвестный элемент. (М300) для TextField и Button аналогично. Могу предположить, что из-за более новой верси…
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Now discuss on the forum
Evgenii LegotckoiJune 25, 2024, 1:11 a.m.
t
google domain [url=https://google.com/]domain[/url] domain [http://www.example.com link title]
tonypeachey1Nov. 15, 2024, 5:04 p.m.
NSProjectJune 4, 2022, 1:49 p.m.
IscanderCheNov. 1, 2024, 1:43 a.m.
Машина тьюринга // Начальное состояние 0 0, ,<,1 // Переход в состояние 1 при пустом символе 0,0,>,0 // Остаемся в состоянии 0, двигаясь вправо при встрече 0 0,1,>…