<?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[Dockable windows &#x2F; widgets in Qt]]></title><description><![CDATA[<p dir="auto">Hello!</p>
<p dir="auto">Dockable widgets in Qt are possible (example). However, usually one can dock a widget in a dockable area of a larger surrounding parent frame. I wonder whether there is a way to attach floating windows with each other, as it is possible in WinAmp (see screenshot).<br />
Can someone point out whether something like this can be done with Qt?</p>
<p dir="auto">!<a href="http://i.stack.imgur.com/igajc.png(winamp)" target="_blank" rel="noopener noreferrer nofollow ugc">http://i.stack.imgur.com/igajc.png(winamp)</a>!</p>
<p dir="auto">What i tried so far: Created a second QMainWindow which overrides the moveEvent(QMoveEvent * event) function and calculate the distance to the parent QMainWindow (line 8). If the second window is near to the parent window, i move it directly next to the parent window (line 13).<br />
My Problem with this approach: After i moved the second window, the mouse key is still pressed and the window moves back to the position before i automatically moved it.</p>
<p dir="auto">My code example right now only works if you try to dock it on the left side of the parent window.<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> playlistWindow::moveEvent(QMoveEvent * event){<br />
// Get positions of the two QMainWindows<br />
QPoint childPosition = event-&gt;pos();<br />
int frameWidth = this-&gt;frameGeometry().width() - this-&gt;width();<br />
QPoint parentPosition = this-&gt;parentWidget()-&gt;pos();</p>
<pre><code>// Calculate distance to parent Window
int diffRight = parentPosition.x() - childPosition.x() - this-&gt;width() - frameWidth;

// If it is near, move it to the frame of the parent window
if( diffRight &gt; 5 &amp;&amp; diffRight &lt; 30 &amp;&amp; !isDocked){
    isDocked = true;
    this-&gt;move(childPosition.x() + diffRight, childPosition.y());
} else {      
    if(diffRight &gt; 30){
        isDocked = false;
    } 
}
</code></pre>
<p dir="auto">}@<br />
Is this the right way to do it?</p>
<p dir="auto">Thanks for your help,</p>
<p dir="auto">Buhmann</p>
]]></description><link>https://forum.qt.io/topic/45311/dockable-windows-widgets-in-qt</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Apr 2026 12:01:59 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/45311.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 27 Aug 2014 21:54:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Dockable windows &#x2F; widgets in Qt on Thu, 28 Aug 2014 06:31:01 GMT]]></title><description><![CDATA[<p dir="auto">There is no build-in mechanism in Qt that would do this job for you. I recommend asking/ taking a look at the code of <em>Qmmp</em> player. It's written in Qt and has exactly the same behaviour you describe.</p>
]]></description><link>https://forum.qt.io/post/241546</link><guid isPermaLink="true">https://forum.qt.io/post/241546</guid><dc:creator><![CDATA[sierdzio]]></dc:creator><pubDate>Thu, 28 Aug 2014 06:31:01 GMT</pubDate></item></channel></rss>