<?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[Background problem witch QMdiSubWindow and paintEvent]]></title><description><![CDATA[<p dir="auto">Hi,<br />
I'm programming a little application using QMainWindow and a sub class of QMdiSubWindow. I use a sub class to plot a grid in the background of mdi subwindows using paintEvent and QPainter.<br />
All work was do using the common way and documented, but when one mdi subwindow are moved over the other the background of the bottom windows is not updated.<br />
I was try to make a screen capture of the problem, but when pressed any button or change the application  focus, the subwindows background is updated.<br />
In the bottom I add some fragments of used source code.<br />
If you know whats is the problem or have some idea, please, tellme.<br />
Thanks a lot!</p>
<p dir="auto">Sergio</p>
<p dir="auto">/***** QMainWindow constructor *****/<br />
MainWindow::MainWindow(QWidget *parent) :<br />
QMainWindow(parent),<br />
ui(new Ui::MainWindow){</p>
<pre><code>ui-&gt;setupUi(this);
</code></pre>
<p dir="auto">// Add two subwindow to test the problem<br />
this-&gt;ui-&gt;mdiArea-&gt;addSubWindow(new subWnd());<br />
this-&gt;ui-&gt;mdiArea-&gt;addSubWindow(new subWnd());<br />
}</p>
<p dir="auto">/***** subWnd class definition *****/</p>
<p dir="auto">class subWnd : public QMdiSubWindow<br />
{<br />
public:<br />
subWnd();<br />
protected:<br />
virtual void paintEvent(QPaintEvent * event);<br />
};</p>
<p dir="auto">/***** and class implementation *****/<br />
#include "subwnd.h"<br />
#include &lt;QPainter&gt;<br />
#include &lt;QPaintEvent&gt;</p>
<p dir="auto">subWnd::subWnd(){</p>
<pre><code>setAttribute(Qt::WA_DeleteOnClose);
</code></pre>
<p dir="auto">}</p>
<p dir="auto">int cordToGrid(int v)<br />
{<br />
int ret;<br />
ret = v / 5;<br />
ret = ret * 5;<br />
return ret;<br />
}<br />
void subWnd::paintEvent(QPaintEvent * event){</p>
<pre><code>QPen lapiz(Qt::black);
QBrush relleno(Qt::white);
QPainter painter(this);
lapiz.setWidth(1);
lapiz.setStyle(Qt::DashLine);
relleno.setStyle(Qt::NoBrush);
painter.setPen(lapiz);
painter.setBrush(relleno);
int xIni = cordToGrid(event-&gt;rect().x());
int yIni = cordToGrid(event-&gt;rect().y());
for(int x = xIni; x &lt; event-&gt;rect().width();x += 5)
   for(int y = yIni; y &lt; event-&gt;rect().height(); y += 5)
        painter.drawPoint(x, y);
painter.end();
QMdiSubWindow::paintEvent(event);
</code></pre>
<p dir="auto">}</p>
]]></description><link>https://forum.qt.io/topic/79386/background-problem-witch-qmdisubwindow-and-paintevent</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 04:05:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/79386.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 18 May 2017 10:04:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Background problem witch QMdiSubWindow and paintEvent on Thu, 18 May 2017 20:38:55 GMT]]></title><description><![CDATA[<p dir="auto">Hi and welcome to devnet,</p>
<p dir="auto">AFAIK, the usual way is to create a custom widget with the custom painting you want and set it as internal widget of the QMdiSubWindow.</p>
]]></description><link>https://forum.qt.io/post/394321</link><guid isPermaLink="true">https://forum.qt.io/post/394321</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Thu, 18 May 2017 20:38:55 GMT</pubDate></item></channel></rss>