<?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[Get  rect of widget]]></title><description><![CDATA[<p dir="auto">Hello</p>
<p dir="auto">The question is</p>
<p dir="auto">How and when to get the rect of widget   ?</p>
<p dir="auto">I know the function rect but...</p>
<p dir="auto">I have a desktop app and I created dinamicaly  the widgets ( one QTabWidget with 3 tabs<br />
and each tab contains few  QGroupBoxes with different layouts and some widgets inside ).<br />
I set the size and the postion of main screen at the beginning before call show();</p>
<p dir="auto">I want to know the rect of one widget from one groupbox from one tab after the app is created and showed<br />
in order to draw something  in that widget.</p>
<p dir="auto">I do not know when and where to get the rect of that widget.<br />
When I created that widget the rect is not correct.</p>
<p dir="auto">This is code for one groupbox created for one tab</p>
<p dir="auto">void CalculTab::createGroupBoxGraphic2()<br />
{<br />
m_pGroupG2 = new QGroupBox(tr("G2"));</p>
<pre><code>QHBoxLayout *layout = new QHBoxLayout;
</code></pre>
<p dir="auto">// this is my widget<br />
GLWidget *openGL = new GLWidget(&amp;m_graphic2, this);</p>
<pre><code>layout-&gt;addWidget(openGL);

m_pGroupG2-&gt;setLayout(layout);

// the value is not correct !!!
QRect rcG2 = openGL-&gt;rect();
</code></pre>
<p dir="auto">}</p>
<p dir="auto">For test I added mousePressEvent for GLWidget .<br />
After the app is created and showed, when I click I can get the correct recatngle.</p>
<p dir="auto">void GLWidget::mousePressEvent(QMouseEvent *e)<br />
{<br />
// correct<br />
QRect rcG2 = this-&gt;rect();</p>
<p dir="auto">}</p>
<p dir="auto">I hope you can understand what I want.</p>
]]></description><link>https://forum.qt.io/topic/73789/get-rect-of-widget</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 17:56:41 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/73789.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 27 Nov 2016 15:10:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Get  rect of widget on Sun, 27 Nov 2016 15:38:01 GMT]]></title><description><![CDATA[<p dir="auto">This is what I meant, yes.</p>
]]></description><link>https://forum.qt.io/post/361881</link><guid isPermaLink="true">https://forum.qt.io/post/361881</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Sun, 27 Nov 2016 15:38:01 GMT</pubDate></item><item><title><![CDATA[Reply to Get  rect of widget on Sun, 27 Nov 2016 15:32:59 GMT]]></title><description><![CDATA[<p dir="auto">Maybe in this function  GLWidget::paintEvent(QPaintEvent *event)</p>
<p dir="auto">GLWidget is my widget and I pass the rect to other object m_graphic which will do some.</p>
<p dir="auto">But I am not sure that is the best solution.</p>
<p dir="auto">void GLWidget::paintEvent(QPaintEvent *event)<br />
{<br />
QRect rect = event-&gt;rect();</p>
<pre><code>m_graphic-&gt;SetRecatangleGraphic(rect);

QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
m_graphic-&gt;paint(&amp;painter, event);
painter.end();
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://forum.qt.io/post/361878</link><guid isPermaLink="true">https://forum.qt.io/post/361878</guid><dc:creator><![CDATA[aliosa]]></dc:creator><pubDate>Sun, 27 Nov 2016 15:32:59 GMT</pubDate></item><item><title><![CDATA[Reply to Get  rect of widget on Sun, 27 Nov 2016 15:19:16 GMT]]></title><description><![CDATA[<p dir="auto">Hello</p>
<p dir="auto">I need to know that rect because I want to pass to other class and  make some calculation.</p>
<p dir="auto">Thank you for your answer but it is not what I need.</p>
<p dir="auto">I want to know when and where I can obtain the correct rectangle of one widget.<br />
Maybe it is an event which can tell me that app is created and all the size and position of controls are  ready.</p>
]]></description><link>https://forum.qt.io/post/361877</link><guid isPermaLink="true">https://forum.qt.io/post/361877</guid><dc:creator><![CDATA[aliosa]]></dc:creator><pubDate>Sun, 27 Nov 2016 15:19:16 GMT</pubDate></item><item><title><![CDATA[Reply to Get  rect of widget on Sun, 27 Nov 2016 15:13:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/aliosa">@<bdi>aliosa</bdi></a> said in <a href="/post/361874">Get rect of widget</a>:</p>
<blockquote>
<p dir="auto">I want to know the rect of one widget from one groupbox from one tab after the app is created and showed<br />
in order to draw something  in that widget.</p>
</blockquote>
<p dir="auto">Just draw in the <code>paintEvent</code> override, don't try to guess when the widget is shown or hidden or what the intermediate heights are, it's not going to work well.</p>
]]></description><link>https://forum.qt.io/post/361875</link><guid isPermaLink="true">https://forum.qt.io/post/361875</guid><dc:creator><![CDATA[kshegunov]]></dc:creator><pubDate>Sun, 27 Nov 2016 15:13:35 GMT</pubDate></item></channel></rss>