<?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[Adding Custom QWidget to QMainWindow]]></title><description><![CDATA[<p dir="auto">Hello.</p>
<p dir="auto">I have QMainWindow based class GWindow with *.ui and also have custom QWidget based class Frame and I want to add Frame object to GWindow.</p>
<pre><code>GWindow ::GWindow (QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    setWindowFlags(Qt::FramelessWindowHint);
  
    FrameObject.show();
    this-&gt;setCentralWidget(&amp;FrameObject);
}
</code></pre>
<p dir="auto">and Frame class . I added QPushButton for Frame UI in Qt Designer</p>
<pre><code>class Frame : public QWidget
{
    Q_OBJECT

public:
    Frame (QWidget *parent = 0);
    ~Frame ();

private:
    Ui::Frame ui;
};

Frame ::Frame (QWidget *parent)
    : QWidget(parent)
{
  ui.setupUi(this);
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/63966/adding-custom-qwidget-to-qmainwindow</link><generator>RSS for Node</generator><lastBuildDate>Tue, 15 Sep 2026 17:46:32 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/63966.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 09 Feb 2016 14:26:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Adding Custom QWidget to QMainWindow on Tue, 09 Feb 2016 16:30:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a><br />
Hello,<br />
<code>Ui::WindowTitle</code> is your form class and not a widget. The widget I'm suggesting you initialize with it is the central widget of the main window, and the central widget will be resized automatically to fit the client area of the window.</p>
<blockquote>
<p dir="auto">mywidget-&gt;setGeometry(0,0,  parentWidget.widht(), 100);</p>
</blockquote>
<p dir="auto">You shouldn't be wanting to do that. Just put the appropriate layout and setup your widgets in the designer. If any of them is fixed size put that in the appropriate properties of the object (the right side of the designer, after clicking on an object).</p>
<p dir="auto">Kind regards.</p>
]]></description><link>https://forum.qt.io/post/312265</link><guid isPermaLink="true">https://forum.qt.io/post/312265</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Tue, 09 Feb 2016 16:30:34 GMT</pubDate></item><item><title><![CDATA[Reply to Adding Custom QWidget to QMainWindow on Tue, 09 Feb 2016 16:27:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kshegunov">@<bdi>kshegunov</bdi></a></p>
<p dir="auto">But If I want use not fixed size widgets? How can I resize Ui::WindowTitle titleUi; custom widget?</p>
<p dir="auto">I want to set size dynamically, for example:</p>
<pre><code>mywidget-&gt;setGeometry(0,0,  parentWidget.widht(), 100);
</code></pre>
]]></description><link>https://forum.qt.io/post/312263</link><guid isPermaLink="true">https://forum.qt.io/post/312263</guid><dc:creator><![CDATA[Alatriste]]></dc:creator><pubDate>Tue, 09 Feb 2016 16:27:39 GMT</pubDate></item><item><title><![CDATA[Reply to Adding Custom QWidget to QMainWindow on Tue, 09 Feb 2016 15:55:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alatriste">@<bdi>Alatriste</bdi></a><br />
Hello,</p>
<p dir="auto">What about:</p>
<pre><code>SandBox::SandBox(QWidget * parent)
    :  QMainWindow(parent, Qt::FramelessWindowHint)
{
    ui.setupUi(this);

    Ui::WindowTitle titleUi;  //&lt; This could be put as a class member as well
    titleUi.setupUi(centralWidget());
}
</code></pre>
<p dir="auto">You don't seem to be doing anything special with your <code>WindowTitle</code> class, so no need to derive <code>QWidget</code> only to set up a form.</p>
<p dir="auto">Kind regards.</p>
]]></description><link>https://forum.qt.io/post/312256</link><guid isPermaLink="true">https://forum.qt.io/post/312256</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Tue, 09 Feb 2016 15:55:46 GMT</pubDate></item><item><title><![CDATA[Reply to Adding Custom QWidget to QMainWindow on Tue, 09 Feb 2016 14:57:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a></p>
<p dir="auto">Now WindowTitle instead of Frame and Sandbox intead of GWindow</p>
<pre><code>class WindowTitle : public QWidget
{
    Q_OBJECT

public:
    WindowTitle(QWidget *parent = 0);
    ~WindowTitle();

private:
    Ui::WindowTitle ui;
};


WindowTitle::WindowTitle(QWidget *parent)
    : QWidget(parent)
{
  ui.setupUi(this);
}

WindowTitle::~WindowTitle()
{

}
</code></pre>
<pre><code>#include &lt;QtWidgets/QMainWindow&gt;
#include "WindowTitle.h"
#include &lt;QGridLayout&gt;
#include "ui_SandBox.h"

class SandBox : public QMainWindow
{
    Q_OBJECT

public:
    SandBox(QWidget *parent = 0);
    ~SandBox();

private:
    Ui::SandBoxClass ui;
    
};

#include "SandBox.h"

SandBox::SandBox(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
  
    setWindowFlags(Qt::FramelessWindowHint);

    QWidget * widget = new QWidget;
    QGridLayout * layout = new QGridLayout;
    WindowTitle * w = new WindowTitle;
    
    w-&gt;show();
    layout-&gt;addWidget(w,0,0,1,1);
    widget-&gt;setLayout(layout);
    setCentralWidget(widget);
}

</code></pre>
]]></description><link>https://forum.qt.io/post/312240</link><guid isPermaLink="true">https://forum.qt.io/post/312240</guid><dc:creator><![CDATA[Alatriste]]></dc:creator><pubDate>Tue, 09 Feb 2016 14:57:27 GMT</pubDate></item><item><title><![CDATA[Reply to Adding Custom QWidget to QMainWindow on Tue, 09 Feb 2016 14:48:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alatriste">@<bdi>Alatriste</bdi></a><br />
the issue has to be somewhere in the code you haven't posted yet. :)</p>
]]></description><link>https://forum.qt.io/post/312238</link><guid isPermaLink="true">https://forum.qt.io/post/312238</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 09 Feb 2016 14:48:29 GMT</pubDate></item><item><title><![CDATA[Reply to Adding Custom QWidget to QMainWindow on Tue, 09 Feb 2016 14:44:04 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/raven-worx">@<bdi>raven-worx</bdi></a> said:</p>
<blockquote>
<p dir="auto">is FrameObject?<br />
Where and how is it defined?</p>
</blockquote>
<p dir="auto">into GWindow header</p>
<pre><code>class GWindow : public QMainWindow
{
    Q_OBJECT

public:
    GWindow (QWidget *parent = 0);
    ~GWindow ();

private:
    Ui::SandBoxClass ui;
    Frame FrameObject;    
};
</code></pre>
]]></description><link>https://forum.qt.io/post/312236</link><guid isPermaLink="true">https://forum.qt.io/post/312236</guid><dc:creator><![CDATA[Alatriste]]></dc:creator><pubDate>Tue, 09 Feb 2016 14:44:04 GMT</pubDate></item><item><title><![CDATA[Reply to Adding Custom QWidget to QMainWindow on Tue, 09 Feb 2016 14:39:26 GMT]]></title><description><![CDATA[<p dir="auto">what is FrameObject?<br />
Where and how is it defined?</p>
]]></description><link>https://forum.qt.io/post/312234</link><guid isPermaLink="true">https://forum.qt.io/post/312234</guid><dc:creator><![CDATA[raven-worx]]></dc:creator><pubDate>Tue, 09 Feb 2016 14:39:26 GMT</pubDate></item></channel></rss>