<?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 your own function to QFrame or any other class]]></title><description><![CDATA[<p dir="auto">How can i add my own function to QFrame Class so that i can use it with the QFrame object.</p>
]]></description><link>https://forum.qt.io/topic/79943/adding-your-own-function-to-qframe-or-any-other-class</link><generator>RSS for Node</generator><lastBuildDate>Mon, 21 Sep 2026 07:50:33 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/79943.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 05 Jun 2017 07:52:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Adding your own function to QFrame or any other class on Mon, 05 Jun 2017 10:28:14 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahti">@<bdi>Ahti</bdi></a> said in <a href="/post/397337">Adding your own function to QFrame or any other class</a>:</p>
<blockquote>
<p dir="auto">autofillbackground</p>
</blockquote>
<p dir="auto"><a href="http://doc.qt.io/qt-5/qwidget.html#autoFillBackground-prop" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qwidget.html#autoFillBackground-prop</a></p>
<p dir="auto">Basically,  it controls if the background is filled before the Paint is called.</p>
]]></description><link>https://forum.qt.io/post/397339</link><guid isPermaLink="true">https://forum.qt.io/post/397339</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 05 Jun 2017 10:28:14 GMT</pubDate></item><item><title><![CDATA[Reply to Adding your own function to QFrame or any other class on Mon, 05 Jun 2017 10:26:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> I already created that generic function :D thanks anyways :) what does autofillbackground method does btw ?</p>
]]></description><link>https://forum.qt.io/post/397337</link><guid isPermaLink="true">https://forum.qt.io/post/397337</guid><dc:creator><![CDATA[Ahti]]></dc:creator><pubDate>Mon, 05 Jun 2017 10:26:15 GMT</pubDate></item><item><title><![CDATA[Reply to Adding your own function to QFrame or any other class on Mon, 05 Jun 2017 09:12:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahti">@<bdi>Ahti</bdi></a><br />
Np :)<br />
If you need many of them , just make it a function and call it pr Frame.</p>
<pre><code>void AddDrop(QFrame * frame )  {
if (!frame) return;
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
    effect-&gt;setBlurRadius(5);
    effect-&gt;setXOffset(5);
    effect-&gt;setYOffset(5);
    effect-&gt;setColor(Qt::black);
    frame-&gt;setAutoFillBackground(true);
    frame-&gt;setGraphicsEffect(effect);
}
</code></pre>
<p dir="auto">and call it from mainwin (after setupUI ) like<br />
AddDrop(ui-&gt;frame1);<br />
AddDrop(ui-&gt;frame2);<br />
AddDrop(ui-&gt;frame3);<br />
etc</p>
]]></description><link>https://forum.qt.io/post/397323</link><guid isPermaLink="true">https://forum.qt.io/post/397323</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 05 Jun 2017 09:12:16 GMT</pubDate></item><item><title><![CDATA[Reply to Adding your own function to QFrame or any other class on Mon, 05 Jun 2017 09:06:02 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> Thanks :)</p>
]]></description><link>https://forum.qt.io/post/397320</link><guid isPermaLink="true">https://forum.qt.io/post/397320</guid><dc:creator><![CDATA[Ahti]]></dc:creator><pubDate>Mon, 05 Jun 2017 09:06:02 GMT</pubDate></item><item><title><![CDATA[Reply to Adding your own function to QFrame or any other class on Mon, 05 Jun 2017 09:05:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahti">@<bdi>Ahti</bdi></a><br />
Hi<br />
You can just create your own subclass</p>
<pre><code>#include &lt;QFrame&gt;

class MyFrame : public QFrame {
  Q_OBJECT
 public:
 void drawshadow(.....) /// your func
  MyFrame(QWidget* parent = 0, Qt::WindowFlags f = 0): QFrame(parent, f) {
  }
 protected:
  virtual void paintEvent(QPaintEvent* e) override {
    QFrame::paintEvent(e); // pass event to base class
  }
};
</code></pre>
<p dir="auto">But there a note:<br />
You cannot draw outside of the QFrame. So keep that in mind.<br />
Also you cannot use a Painter object outside of paintEvent.<br />
But if you use the Effect classes, it might work.<br />
<a href="http://doc.qt.io/qt-5/qgraphicsdropshadoweffect.html" target="_blank" rel="noopener noreferrer nofollow ugc">http://doc.qt.io/qt-5/qgraphicsdropshadoweffect.html</a></p>
<p dir="auto">So if its ok the shadow is inside the QFrame area, then u can use the paintEvent.<br />
Elese the qgraphicsdropshadoweffect might help you out.</p>
<p dir="auto">If you just need a shadow, it can be done with no function inside class.</p>
<pre><code>QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
    effect-&gt;setBlurRadius(5);
    effect-&gt;setXOffset(5);
    effect-&gt;setYOffset(5);
    effect-&gt;setColor(Qt::black);
    ui-&gt;frame-&gt;setAutoFillBackground(true);
    ui-&gt;frame-&gt;setGraphicsEffect(effect);
</code></pre>
<p dir="auto"><img src="http://imagizer.imageshack.com/img924/3558/0cQ4Gf.png" alt="alt text" class=" img-fluid img-markdown" /></p>
<p dir="auto"><strong>Updated code to use setAutoFillBackground so drop is not drawn inside.</strong></p>
]]></description><link>https://forum.qt.io/post/397316</link><guid isPermaLink="true">https://forum.qt.io/post/397316</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 05 Jun 2017 09:05:05 GMT</pubDate></item><item><title><![CDATA[Reply to Adding your own function to QFrame or any other class on Mon, 05 Jun 2017 08:29:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a> I simply wanna add a function namely "Drawshadow" of my own which would draw shadow around the borders of QFrame object.</p>
<p dir="auto">This is what i wanna do:</p>
<pre><code>QFrame test ;
test.drawshadow(...);
</code></pre>
<p dir="auto">but before i use drawshadow(); function i must have to first define it in the QFrame class so that QFrame object ( in this case test ) would work.</p>
]]></description><link>https://forum.qt.io/post/397314</link><guid isPermaLink="true">https://forum.qt.io/post/397314</guid><dc:creator><![CDATA[Ahti]]></dc:creator><pubDate>Mon, 05 Jun 2017 08:29:10 GMT</pubDate></item><item><title><![CDATA[Reply to Adding your own function to QFrame or any other class on Mon, 05 Jun 2017 07:54:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/ahti">@<bdi>Ahti</bdi></a></p>
<p dir="auto">Used it where ?<br />
You can always subclass a QFrame.</p>
]]></description><link>https://forum.qt.io/post/397310</link><guid isPermaLink="true">https://forum.qt.io/post/397310</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 05 Jun 2017 07:54:53 GMT</pubDate></item></channel></rss>