<?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[Interactive bezier spline editing within a mainwindow UI]]></title><description><![CDATA[<p dir="auto">Hey guys,</p>
<p dir="auto">I want to add a widget into my mainwindow UI where the user can drag the control points of a cubic bezier curve to reshape it how they see fit. I envision that this would involve some kind of QPainterPath instance tied with some mouse event logic. And I know that QPainterPath has a cubicTo function which creates a cubic bezier curve where you input the end point and control points, so I'm wondering if I could link up the mouse event logic to those control points to move the bezier around. As you can see I have a basic idea, but I have hit a wall with the little details and am having trouble understanding how all of this connects and how to properly implement this. If anyone can offer a solution for how to accomplish this, I would appreciate it dearly.</p>
<p dir="auto">I don't really have any code to share because I haven't been able to get the QPainterPath to work with my UI :(<br />
Any guidance would be greatly appreciated.</p>
<p dir="auto">~Luke</p>
]]></description><link>https://forum.qt.io/topic/164929/interactive-bezier-spline-editing-within-a-mainwindow-ui</link><generator>RSS for Node</generator><lastBuildDate>Thu, 10 Sep 2026 05:39:53 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164929.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 Jul 2026 01:20:57 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Tue, 28 Jul 2026 07:23:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lukester88">@<bdi>lukester88</bdi></a> said in <a href="/post/839419">Interactive bezier spline editing within a mainwindow UI</a>:</p>
<blockquote>
<pre><code>customGraphicsScene *customScene;

ui-&gt;graphicsView_2-&gt;setScene(customScene);  
</code></pre>
</blockquote>
<p dir="auto">Think about it!  <code>customScene</code> is just a <em>pointer</em> to some <code>customGraphicsScene</code> (and an uninitialized pointer at that).  You have not allocated any actual <code>customGraphicsScene</code> instance for it to point it.  I did say earlier:</p>
<blockquote>
<p dir="auto">create a <code>new QGraphicsScene</code> and assign it to the <code>QGraphcisView</code> via <code>graphicsView-&gt;setScene()</code>.</p>
</blockquote>
<p dir="auto">you need to:</p>
<pre><code class="language-cpp">customGraphicsScene *customScene = new customGraphicsScene(this);
ui-&gt;graphicsView_2-&gt;setScene(customScene);
</code></pre>
<p dir="auto">But a couple of points:</p>
<ul>
<li>
<p dir="auto">Your <code>customGraphicsScene *customScene</code> is a <em>local variable</em> in the <code>MainWindow</code> constructor.  Once that exits the local variable no longer exists, you have allocated a <code>customGraphicsScene</code> but you really can no longer get at it to do anything!  You will want that pointer to be a member variable in your <code>MainWindow</code> class.</p>
</li>
<li>
<p dir="auto"><code>class customGraphicsScene : public QGraphicsScene</code>: make <em>all</em> your classes start with an uppercase letter.  All Qt's do, and this is standard practice for C++.  Your variables, such as [now] <code>CustomGraphicsScene *customScene</code>, should indeed start with a lowercase letter.</p>
</li>
</ul>
]]></description><link>https://forum.qt.io/post/839423</link><guid isPermaLink="true">https://forum.qt.io/post/839423</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 28 Jul 2026 07:23:37 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Tue, 28 Jul 2026 00:27:45 GMT]]></title><description><![CDATA[<p dir="auto">custom class header:</p>
<pre><code>


class customGraphicsScene : public QGraphicsScene {

    Q_OBJECT

protected:

    void mousePressEvent(QGraphicsSceneMouseEvent *event) override;

};

</code></pre>
<p dir="auto">class source file:</p>
<pre><code>

void customGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event) {
    if (event-&gt;button() == Qt::LeftButton) {
        qDebug() &lt;&lt; "clicked!";
    }
}
</code></pre>
<p dir="auto">mainwindow implementation:</p>
<pre><code>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);

    customGraphicsScene *customScene;

    ui-&gt;graphicsView_2-&gt;setScene(customScene);   
}

MainWindow::~MainWindow()
{
    delete ui;
}
</code></pre>
]]></description><link>https://forum.qt.io/post/839419</link><guid isPermaLink="true">https://forum.qt.io/post/839419</guid><dc:creator><![CDATA[lukester88]]></dc:creator><pubDate>Tue, 28 Jul 2026 00:27:45 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Tue, 28 Jul 2026 00:14:02 GMT]]></title><description><![CDATA[<p dir="auto">Thank you! I have been working on implementing this method in my code, and I think I am 99% of the way there. I have created a subclass of QGraphicsScene. However, I am running into a segmentation fault when running the debugger, and when I try to run the application, it terminates abnormally and doesn't show the UI.</p>
]]></description><link>https://forum.qt.io/post/839418</link><guid isPermaLink="true">https://forum.qt.io/post/839418</guid><dc:creator><![CDATA[lukester88]]></dc:creator><pubDate>Tue, 28 Jul 2026 00:14:02 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Mon, 27 Jul 2026 15:29:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lukester88">@<bdi>lukester88</bdi></a></p>
<ul>
<li>
<p dir="auto">To access the mouse you will need to use <code>mousePressEvent()</code> and <code>mouseMoveEvent()</code> methods.  These are available on both the <code>QGraphicsView</code> and <code>QGraphicsScene</code>.  A mouse event is sent first to the view and then to its scene.  In both cases these are <code>virtual protected</code> methods.  That means you have to <em>subclass</em> the view/scene to intercept them.</p>
</li>
<li>
<p dir="auto">If you wanted to use them at the view level you would need to create your own <code>QGraphicsView</code> subclass.  Since you want to use <strong>Designer</strong> you would need to use its <em>promotion</em> feature to create a subclassed <code>QGraphicsView</code> at design-time.</p>
</li>
<li>
<p dir="auto">However, I think you will be happy using them at the <code>QGraphicsScene</code> level, where they have been translated into a <code>QGraphicsSceneMouseEvent</code>.  So you will need to create your own subclass of <code>QGraphicsScene</code> to override the methods.  Since you assign the scene to the view in your own code it's easy to just assign your subclassed instance.  In those overridden methods you do whatever to the points of your curve.</p>
</li>
<li>
<p dir="auto">If you need to see mouse events on a <code>QGraphicsItem</code>, like <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> mentioned, then similarly there are the same methods on those and you would subclass the items you add to the scene.</p>
</li>
</ul>
<p dir="auto">So to repeat: I <em>think</em> you will want to use mouse events on the graphics items or scene rather than on the view.</p>
<p dir="auto">P.S.<br />
Just came across <a href="https://stackoverflow.com/questions/18817538/how-to-use-mouse-move-event-for-qgraphicsscene" target="_blank" rel="noopener noreferrer nofollow ugc">how to use mouse move event for QGraphicsScene?</a> from years ago.  Might be worth looking at.</p>
]]></description><link>https://forum.qt.io/post/839408</link><guid isPermaLink="true">https://forum.qt.io/post/839408</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 27 Jul 2026 15:29:45 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Sun, 26 Jul 2026 22:43:31 GMT]]></title><description><![CDATA[<p dir="auto">Thank you! I ended spending some time today learning the basics of QGraphicsView and QPainter. I am able to get as far as plotting a cubic bezier using the cubicTo() function from QPainterPath, and then sending that path to the QGraphicsScene to be viewed in QGraphicsView. However, my next problem is getting mouse events to work. I have read the documentation on the QGraphicsView mouse event system, and it looks like Qt recommends subclassing a QWidget to create a custom graphics view class where I would override the virtual mouse event functions. I understand the basic idea, but can you explain how I would go about retrieving and using mouse event data from the QGraphicsView? Thank you</p>
]]></description><link>https://forum.qt.io/post/839404</link><guid isPermaLink="true">https://forum.qt.io/post/839404</guid><dc:creator><![CDATA[lukester88]]></dc:creator><pubDate>Sun, 26 Jul 2026 22:43:31 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Sun, 26 Jul 2026 07:47:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lukester88">@<bdi>lukester88</bdi></a> said in <a href="/post/839383">Interactive bezier spline editing within a mainwindow UI</a>:</p>
<blockquote>
<p dir="auto">am having trouble figuring out how to get started on implementing this into an existing mainwindow UI.</p>
</blockquote>
<ul>
<li>
<p dir="auto">In <strong>Designer</strong> from the toolbox at the left, section <strong>Display Widgets</strong>, drag a <strong>Graphics View</strong> onto the central widget in your <strong>MainWindow</strong>.  This is a <em>widget</em>, just like all the other widgets there (e.g. <strong>Label</strong>, <strong>Line Edit</strong>, <strong>Frame</strong> etc.), so you can put it wherever you could put those and do all the usual layout stuff and so on.  This gives you a <code>QGraphicsView</code> widget named <code>graphicsView</code>.</p>
</li>
<li>
<p dir="auto">A <code>QGraphicsView</code> needs a <code>QGraphicsScene</code> as its "model", but you cannot create that from <strong>Designer</strong>.  Somewhere in your code --- probably in the <strong>MainWindow</strong> constructor after the <code>ui-&gt;setupUi(this)</code> --- create a <code>new QGraphicsScene</code> and assign it to the <code>QGraphcisView</code> via <code>graphicsView-&gt;setScene()</code>.</p>
</li>
<li>
<p dir="auto">Now you have a graphics view with a graphics scene behind it.  You can start creating your <code>QGraphicsItem</code>s and adding them onto the scene.  They will be visualized in the view.  You can do whatever to the scene or view to alter its look and behaviour.</p>
</li>
</ul>
]]></description><link>https://forum.qt.io/post/839385</link><guid isPermaLink="true">https://forum.qt.io/post/839385</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sun, 26 Jul 2026 07:47:06 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Sun, 26 Jul 2026 02:39:55 GMT]]></title><description><![CDATA[<p dir="auto">Also, I am using Qt 6 with C++, and usually do all my coding in the Qt Creator IDE.</p>
]]></description><link>https://forum.qt.io/post/839384</link><guid isPermaLink="true">https://forum.qt.io/post/839384</guid><dc:creator><![CDATA[lukester88]]></dc:creator><pubDate>Sun, 26 Jul 2026 02:39:55 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Sun, 26 Jul 2026 02:17:13 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for the reply! I am aware of the availability of QGraphicsItem and QPainterPath. I have read through the documentation but am having trouble figuring out how to get started on implementing this into an existing mainwindow UI. Is it possible you could please provide an example and explanation? Thanks again.</p>
]]></description><link>https://forum.qt.io/post/839383</link><guid isPermaLink="true">https://forum.qt.io/post/839383</guid><dc:creator><![CDATA[lukester88]]></dc:creator><pubDate>Sun, 26 Jul 2026 02:17:13 GMT</pubDate></item><item><title><![CDATA[Reply to Interactive bezier spline editing within a mainwindow UI on Sat, 25 Jul 2026 18:00:48 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">One way you can do that is using the Qt Graphics View framework.<br />
Create a custom QGraphicsItem that you will use to move the curve's reference points and a QPainterPath based on them.</p>
]]></description><link>https://forum.qt.io/post/839376</link><guid isPermaLink="true">https://forum.qt.io/post/839376</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sat, 25 Jul 2026 18:00:48 GMT</pubDate></item></channel></rss>