<?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[Getting the size of the MainWindow]]></title><description><![CDATA[<p dir="auto">Hello,<br />
I want to display an image on the MainWindow of my C++ program under QT, the following code that is in the MainWindow creator maximize the Window and then try to get his size to resize the QImage and the QLabel but the size that i get is the size before it is maximized, i used the following code :<br />
ui-&gt;setupUi (this);<br />
this-&gt;showMaximized ();<br />
szx=this-&gt;size ().width ();<br />
szy=this-&gt;size ().height ();<br />
Can you tell me what is wrong in this ?<br />
Thanks,<br />
JY Giroud</p>
]]></description><link>https://forum.qt.io/topic/164625/getting-the-size-of-the-mainwindow</link><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 16:17:59 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164625.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 30 Apr 2026 20:29:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Getting the size of the MainWindow on Thu, 07 May 2026 19:59:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hskoglund">@<bdi>hskoglund</bdi></a><br />
Using a timer can be anything between a waste of time and vain hope.<br />
It depends on the operating system, how <code>showMaximized()</code>, <code>showNormal()</code> and the like are handled.<br />
<code>QWidget::windowState()</code> reflects what has been ordered to the window manager.</p>
<p dir="auto">The problem is that the widget's geometry can change twice. First time when <code>showMaximized()</code> has been processed and<br />
<code>widget-&gt;windowState().testFlag(Qt::WindowMaximized)</code> returns <code>true</code>.<br />
Second time, when the window manager has applied decorations (i.e. title bar and window handles).</p>
<p dir="auto">A good place to look for inspiration is <code>tst_QWidget::showMaximized()</code> and <code>showFullScreen()</code>.<br />
The QTRY_ macros generally process events until either the predicate is true or a timeout is hit. They're not available in applications, but you can write your own methods that work for your use case.</p>
]]></description><link>https://forum.qt.io/post/838148</link><guid isPermaLink="true">https://forum.qt.io/post/838148</guid><dc:creator><![CDATA[Axel Spoerl]]></dc:creator><pubDate>Thu, 07 May 2026 19:59:44 GMT</pubDate></item><item><title><![CDATA[Reply to Getting the size of the MainWindow on Sat, 02 May 2026 15:28:58 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jyg61">@<bdi>JYG61</bdi></a> simple put your QLabel inside a qscrollArea, then set the ScrollArea  as central widget. No need to worry about the windows size</p>
<p dir="auto">Check this <a href="https://youtu.be/lps8oayHPxs?si=C5kmvyT_W8SOXF4p" target="_blank" rel="noopener noreferrer nofollow ugc">https://youtu.be/lps8oayHPxs?si=C5kmvyT_W8SOXF4p</a></p>
]]></description><link>https://forum.qt.io/post/838085</link><guid isPermaLink="true">https://forum.qt.io/post/838085</guid><dc:creator><![CDATA[Ronel_qtmaster]]></dc:creator><pubDate>Sat, 02 May 2026 15:28:58 GMT</pubDate></item><item><title><![CDATA[Reply to Getting the size of the MainWindow on Fri, 01 May 2026 19:48:37 GMT]]></title><description><![CDATA[<p dir="auto">Hi, to add to <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a> instead of listening to the resizeEvent() you could split the code in your MainWindow creator code into 2 parts using a singleshot lambda, something like this:</p>
<pre><code>...
ui-&gt;setupUi(this);
[other setup code]
showMaximized();
...

QTimer::singleShot(20,this,[this]
{
//  get the size of your (now maximized) main window here
});
// end of MainWindow constructor
</code></pre>
<p dir="auto">(20 millseconds should be enough for the (usually two) resize events to happen.)</p>
]]></description><link>https://forum.qt.io/post/838080</link><guid isPermaLink="true">https://forum.qt.io/post/838080</guid><dc:creator><![CDATA[hskoglund]]></dc:creator><pubDate>Fri, 01 May 2026 19:48:37 GMT</pubDate></item><item><title><![CDATA[Reply to Getting the size of the MainWindow on Fri, 01 May 2026 19:24:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jyg61">@<bdi>JYG61</bdi></a> Going through it twice is not what I would have expected. Which OS are you on ?</p>
<p dir="auto">That said, based on your requirements, <a class="plugin-mentions-user plugin-mentions-a" href="/user/jacek-marcin-jaworski">@<bdi>Jacek-Marcin-Jaworski</bdi></a> is correct, <code>resizeEvent</code> is called on each operation that modifies the size of your widget.</p>
<p dir="auto">By the way, how are you using your QLabel ?</p>
<p dir="auto">Did you consider using <a href="https://doc.qt.io/qt-6/qlabel.html#scaledContents-prop" target="_blank" rel="noopener noreferrer nofollow ugc">QLabel::scaledContents property</a> ?</p>
]]></description><link>https://forum.qt.io/post/838079</link><guid isPermaLink="true">https://forum.qt.io/post/838079</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 01 May 2026 19:24:51 GMT</pubDate></item><item><title><![CDATA[Reply to Getting the size of the MainWindow on Fri, 01 May 2026 10:32:46 GMT]]></title><description><![CDATA[<p dir="auto">You make mistake. You need to use QMainWindow::resizeEvent() in order to receive info that window was resized. Then you can call  QMainWindow::update() in order to repaint whole window.  QMainWindow::showEvent() indicating only that the window appear on the screen to your user, not that the window is updated/resized/repainted.</p>
]]></description><link>https://forum.qt.io/post/838072</link><guid isPermaLink="true">https://forum.qt.io/post/838072</guid><dc:creator><![CDATA[Jacek Marcin Jaworski]]></dc:creator><pubDate>Fri, 01 May 2026 10:32:46 GMT</pubDate></item><item><title><![CDATA[Reply to Getting the size of the MainWindow on Thu, 30 Apr 2026 21:14:30 GMT]]></title><description><![CDATA[<p dir="auto">I added that function<br />
void MainWindow::showEvent(QShowEvent *event)<br />
{<br />
int szx,szy;<br />
szx=this-&gt;size ().width ();<br />
szy=this-&gt;size ().height ();<br />
}<br />
when i put a breakpoint in the line szy=... the value of szx is 800 (the size before the window is maximized), i expected i passed twice in that function :<br />
the first display with the standard size<br />
the second after the maximize function<br />
but it stops only once<br />
after the first stop i pressed F10 to execute one line and then F5 to stop at the next breakpoint but it doesn't stop anymore, maybe i don't understand the way the debugger works.</p>
]]></description><link>https://forum.qt.io/post/838064</link><guid isPermaLink="true">https://forum.qt.io/post/838064</guid><dc:creator><![CDATA[JYG61]]></dc:creator><pubDate>Thu, 30 Apr 2026 21:14:30 GMT</pubDate></item><item><title><![CDATA[Reply to Getting the size of the MainWindow on Thu, 30 Apr 2026 20:57:57 GMT]]></title><description><![CDATA[<p dir="auto">I am not sure i understand well : showEvent () is a method of QMainWindow that run every this the MainWindow is writen, it will run when i call the showMaximized function, i just need to read the size in that method ?</p>
]]></description><link>https://forum.qt.io/post/838063</link><guid isPermaLink="true">https://forum.qt.io/post/838063</guid><dc:creator><![CDATA[JYG61]]></dc:creator><pubDate>Thu, 30 Apr 2026 20:57:57 GMT</pubDate></item><item><title><![CDATA[Reply to Getting the size of the MainWindow on Thu, 30 Apr 2026 20:34:04 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">The showXYZ methods requests the widget to be shown. This won't have happened yet when you call <code>this-&gt;size()</code>.</p>
<p dir="auto">The showEvent method is were you will get the size of your widget once it's shown. Depending on what you want to do, that might be enough.</p>
]]></description><link>https://forum.qt.io/post/838062</link><guid isPermaLink="true">https://forum.qt.io/post/838062</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 30 Apr 2026 20:34:04 GMT</pubDate></item></channel></rss>