<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Solved, sort of] How to draw a wireframe in Qt3D]]></title><description><![CDATA[<p dir="auto">Hello!</p>
<p dir="auto">This is (obviously) a Qt3D oriented post...I wasn't sure where to put this; if it's in the wrong place, let me know.</p>
<p dir="auto">I'm trying to teach myself Qt3D for an upcoming project.  Part of what I need to do is to draw a wireframe of my geometry, however, I can't seem to get Qt3D to behave correctly for me.  I've simplified this down to simply trying to draw one triangle.  I subclass QQuickItem3D to create a new QML element, and use QGLBuilder and QGeometryData to construct a new QGLSceneNode.  However, no matter what I set "setDrawingMode" to, I still end up with a white triangle in my scene, instead of the wanted wireframe.</p>
<p dir="auto">Anyone know anything about Qt3D that can help?</p>
<p dir="auto">EDIT:  I can fix the problem by ignoring the QGLBuilder and the QGLSceneNode, and simply calling the "draw" method on the QGeometryData.</p>
<p dir="auto">Here's my code:</p>
<p dir="auto"><em>Wireframe.h:</em><br />
@<br />
#ifndef WIREFRAME_H<br />
#define WIREFRAME_H</p>
<p dir="auto">#include "qquickitem3d.h"<br />
#include "qglscenenode.h"</p>
<p dir="auto">class Wireframe : public QQuickItem3D<br />
{<br />
Q_OBJECT<br />
public:<br />
Wireframe(QObject *parent = 0);<br />
~Wireframe();</p>
<p dir="auto">protected:<br />
void drawItem(QGLPainter *painter);</p>
<p dir="auto">private:<br />
QGLSceneNode* myScene;<br />
};</p>
<p dir="auto">QML_DECLARE_TYPE(Wireframe)</p>
<p dir="auto">#endif<br />
@</p>
<p dir="auto"><em>Wireframe.cpp:</em><br />
@<br />
#include "Wireframe.h"<br />
#include &lt;QGeometryData&gt;<br />
#include &lt;QGLBuilder&gt;</p>
<p dir="auto">Wireframe::Wireframe(QObject *parent)<br />
: QQuickItem3D(parent)<br />
{<br />
QGLBuilder builder;<br />
QGeometryData geometry;<br />
geometry.appendVertex(QVector3D(0,0,0));<br />
geometry.appendVertex(QVector3D(4,0,0));<br />
geometry.appendVertex(QVector3D(0,4,0));<br />
builder &lt;&lt; geometry;<br />
myScene = builder.finalizedSceneNode();<br />
myScene-&gt;setDrawingMode(QGL::LineLoop);<br />
myScene-&gt;setDrawingWidth(10);<br />
myScene-&gt;setParent(this);<br />
}</p>
<p dir="auto">Wireframe::~Wireframe(){<br />
delete myScene;<br />
}</p>
<p dir="auto">void Wireframe::drawItem(QGLPainter *painter)<br />
{<br />
// Draw the geometry.<br />
myScene-&gt;draw(painter);<br />
}<br />
@</p>
<p dir="auto"><em>main.cpp:</em><br />
@<br />
#include &lt;QApplication&gt;<br />
#include &lt;QQuickView&gt;<br />
#include &lt;QDeclarativeEngine&gt;<br />
#include "Wireframe.h"</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{<br />
QApplication app(argc, argv);<br />
qmlRegisterType&lt;Wireframe&gt;("CustomComponents", 1, 0, "Wireframe");<br />
QSurfaceFormat f;<br />
f.setSamples(16);<br />
QQuickView view;<br />
view.setFormat(f);<br />
view.setResizeMode(QQuickView::SizeRootObjectToView);</p>
<pre><code>view.setSource(QUrl::fromLocalFile&amp;#40;"../wireframe.qml"&amp;#41;&amp;#41;;
</code></pre>
<p dir="auto">#ifdef Q_OS_SYMBIAN<br />
view.setAttribute(Qt::WA_LockLandscapeOrientation, true);<br />
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);<br />
view.showFullScreen();<br />
#else<br />
if (QApplication::arguments().contains(QLatin1String("-maximize")))<br />
view.showMaximized();<br />
else if (QApplication::arguments().contains(QLatin1String("-fullscreen")))<br />
view.showFullScreen();<br />
else<br />
view.show();<br />
#endif</p>
<pre><code>return app.exec&amp;#40;&amp;#41;;
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto"><em>wireframe.qml:</em><br />
@<br />
import QtQuick 2.0<br />
import CustomComponents 1.0<br />
import Qt3D 2.0</p>
<p dir="auto">Rectangle {<br />
width: 640<br />
height: 480<br />
color: "pink"<br />
Viewport {<br />
width: 640; height: 480<br />
Wireframe { id: wf }<br />
}<br />
}<br />
@</p>
]]></description><link>https://forum.qt.io/topic/27070/solved-sort-of-how-to-draw-a-wireframe-in-qt3d</link><generator>RSS for Node</generator><lastBuildDate>Thu, 05 Nov 2026 02:23:20 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/27070.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 09 May 2013 14:20:14 GMT</pubDate><ttl>60</ttl></channel></rss>