<?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[Auto resize the mainwindow to fit the content in the tab widget]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I am working on a multi-tab Qt application and want to shrink or enlarge the main window to fit into the minimum size of the widgets in the active tab. More specifically, the main window shrinks like the following figure when I switch to Tab 1:<br />
<img src="https://i.imgur.com/83AHVxg.png" alt="Tab 1" class=" img-fluid img-markdown" /><br />
and if I switch to Tab 2, the window should enlarge as following:<br />
<img src="https://i.imgur.com/TDEuEg8.png" alt="Tab 2" class=" img-fluid img-markdown" /><br />
The textEdit widget has a minimum size of 300 x 300.<br />
What I have tried is similar to <a href="https://stackoverflow.com/questions/29128936/qtabwidget-size-depending-on-current-tab" target="_blank" rel="noopener noreferrer nofollow ugc">this answer on stackoverflow</a>. I connect the <code>QTabWidget::currentChanged</code> to <code>MainWindow::updateSizes</code> by using <code>connect(ui-&gt;tabWidget, &amp;QTabWidget::currentChanged, this, &amp;MainWindow::updateSizes);</code> in the constructor of <code>MainWindow</code>, and the implementation of <code>MainWindow::updateSizes</code> is:</p>
<pre><code>void MainWindow::updateSizes(int index)
{
  for(int i=0;i&lt;ui-&gt;tabWidget-&gt;count();i++)
      if(i!=index)
          ui-&gt;tabWidget-&gt;widget(i)-&gt;setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);

  ui-&gt;tabWidget-&gt;widget(index)-&gt;setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
  ui-&gt;tabWidget-&gt;widget(index)-&gt;resize(ui-&gt;tabWidget-&gt;widget(index)-&gt;minimumSizeHint());
  ui-&gt;tabWidget-&gt;widget(index)-&gt;adjustSize();
  resize(minimumSizeHint());
  adjustSize();
}
</code></pre>
<p dir="auto">The problem is that the main window is correctly resized when I switch to Tab 2 (see the gif below), but when I switch back to Tab 1, it does not shrink. Any ideas?<br />
<img src="https://i.imgur.com/HIyhTPK.gif" alt="animation" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/topic/119614/auto-resize-the-mainwindow-to-fit-the-content-in-the-tab-widget</link><generator>RSS for Node</generator><lastBuildDate>Tue, 19 May 2026 12:20:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/119614.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 03 Oct 2020 02:34:22 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Auto resize the mainwindow to fit the content in the tab widget on Sat, 03 Oct 2020 12:04:31 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> <a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a><br />
Thanks for your opinion. I will avoid such things and find a better solution.</p>
]]></description><link>https://forum.qt.io/post/620496</link><guid isPermaLink="true">https://forum.qt.io/post/620496</guid><dc:creator><![CDATA[hanatok]]></dc:creator><pubDate>Sat, 03 Oct 2020 12:04:31 GMT</pubDate></item><item><title><![CDATA[Reply to Auto resize the mainwindow to fit the content in the tab widget on Sat, 03 Oct 2020 10:54:45 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hanatok">@<bdi>hanatok</bdi></a> said in <a href="/post/620463">Auto resize the mainwindow to fit the content in the tab widget</a>:</p>
<blockquote>
<p dir="auto">Isn't it possible?</p>
</blockquote>
<p dir="auto">It is, but it would make me as a user go crazy.<br />
You have to set the minimum size for all pages, since this is the size the tabwidget uses.</p>
]]></description><link>https://forum.qt.io/post/620484</link><guid isPermaLink="true">https://forum.qt.io/post/620484</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 03 Oct 2020 10:54:45 GMT</pubDate></item><item><title><![CDATA[Reply to Auto resize the mainwindow to fit the content in the tab widget on Sat, 03 Oct 2020 07:57:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hanatok">@<bdi>hanatok</bdi></a><br />
You probably won't thank me for this, and of course you can do as your please, but can you name an application whose actual main window size keeps growing &amp; shrinking as the user interacts with it in this fashion?  IMHO very disconcerting for user.</p>
]]></description><link>https://forum.qt.io/post/620466</link><guid isPermaLink="true">https://forum.qt.io/post/620466</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Sat, 03 Oct 2020 07:57:34 GMT</pubDate></item><item><title><![CDATA[Reply to Auto resize the mainwindow to fit the content in the tab widget on Sat, 03 Oct 2020 07:28:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> I think Tab 1 has a minimum size, which should be different from the minimum size of Tab 2. When switching back to Tab 1, I want the main window to shrink to fit the minimum size of Tab 1. Isn't it possible?</p>
]]></description><link>https://forum.qt.io/post/620463</link><guid isPermaLink="true">https://forum.qt.io/post/620463</guid><dc:creator><![CDATA[hanatok]]></dc:creator><pubDate>Sat, 03 Oct 2020 07:28:22 GMT</pubDate></item><item><title><![CDATA[Reply to Auto resize the mainwindow to fit the content in the tab widget on Sat, 03 Oct 2020 06:12:15 GMT]]></title><description><![CDATA[<p dir="auto">I don't see a reason why it should shrink. The tab widget now knows that it needs that size so it does not shrink.</p>
]]></description><link>https://forum.qt.io/post/620461</link><guid isPermaLink="true">https://forum.qt.io/post/620461</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 03 Oct 2020 06:12:15 GMT</pubDate></item></channel></rss>