<?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[QFrame subclass with round corners and a custom titlebar]]></title><description><![CDATA[<p dir="auto">Hi all!</p>
<p dir="auto">I'm trying to implement a colorpicker application using Qt6. I have a custom window class  (which will be the main application window) which is a subclass of <code>QFrame</code> and I want it to have round corners. <a href="https://github.com/anoban/colorpicker/blob/main/qt6/include/mainwindow.hpp" target="_blank" rel="noopener noreferrer nofollow ugc">Github link</a><br />
<a href="https://github.com/anoban/colorpicker/tree/main/qt6" target="_blank" rel="noopener noreferrer nofollow ugc">Link to the whole code base is here</a></p>
<ol>
<li>
<p dir="auto">Setting <code>border-radius</code> in  stylesheets alone did not work. I get round corners but there's a rectangular corner underneath the round corner, which defeats the purpose. <img src="https://ddgobkiprc33d.cloudfront.net/a2261109-60ef-4e4f-997d-efbf6b8dbd11.png" alt="Screenshot From 2026-03-26 21-14-12.png" class=" img-fluid img-markdown" /></p>
</li>
<li>
<p dir="auto">Overriding the <code>paintEvent</code> method gave me what I wanted (I had to use <code>setAttribute(Qt::WA_TranslucentBackground)</code> to avoid getting white rectangular corners underneath the rounded corners here) .</p>
</li>
</ol>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/8d08b043-1853-4c27-9829-88678e377982.png" alt="Screenshot From 2026-03-26 21-43-01.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Even though this works, II'm worried about the performance of my implementation. Here's the method implementation.</p>
<pre><code class="language-C++">virtual inline void paintEvent(QPaintEvent* _paint_event) noexcept override {
            QPainter _painter { this };
            _painter.setRenderHint(QPainter::RenderHint::Antialiasing);
            _painter.setBrush(
                QBrush {
                   QColor {
                           _slider_values[configs::rgb_offsets::RED], _slider_values[configs::rgb_offsets::GREEN], _slider_values[configs::rgb_offsets::BLUE] }
            }
            );
            _painter.setPen(Qt::GlobalColor::transparent); // thin borders

            QRect _current_rect { rect() };
            _painter.drawRoundedRect(_current_rect, 10, 0);
            QWidget::paintEvent(_paint_event);
            update(); // without this only the edges of the sliders got painted while the background wasn't responsive???
        }
</code></pre>
<p dir="auto">Without the call to <code>update()</code> at the end of <code>paintEvent()</code>, this is what I got.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/e2e2dc94-2a05-4ccb-a861-be763f16d566.png" alt="Screenshot From 2026-03-26 21-20-11.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">Prior to overriding the <code>paintEvent</code> method, I used the <code>setPalette</code> method to update the background with the current slider values.</p>
<pre><code class="language-C++">        &lsqb;&lsqb;maybe_unused&rsqb;&rsqb; inline void __attribute__((__always_inline__)) __update_bg() noexcept {
            // update the colour palette with the current state of the sliders
            _palette.setColor(
                QPalette::Window,
                QColor { _slider_values[configs::rgb_offsets::RED], _slider_values[configs::rgb_offsets::GREEN], _slider_values[configs::rgb_offsets::BLUE] }
            );
            setPalette(_palette); // set the updated palette, triggering a window redraw
        }
</code></pre>
<p dir="auto">My questions are;</p>
<ol>
<li>Am I doing this in the most efficient way? (I'm not looking for an idiomatic way, I'm more interested performance).</li>
<li>What is the best way to implement the <code>paintEvent</code> method, granted that I only use it for round corners and updating the background colour based on the slider positions?</li>
<li>What's the best way to introduce a custom title bar at the top of this window so it looks like the following image. (i.e. a custom title bar with custom icons)<br />
<img src="https://ddgobkiprc33d.cloudfront.net/fef2adf4-9f72-4a62-9cb0-9caa82827776.png" alt="colorpicker.png" class=" img-fluid img-markdown" /></li>
</ol>
<p dir="auto">Thank you in advance. I'd appreciate any help regarding this.</p>
<p dir="auto">System info:<br />
Qt version 6.10.2 on Fedora Linux 43 (Workstation Edition)</p>
]]></description><link>https://forum.qt.io/topic/164490/qframe-subclass-with-round-corners-and-a-custom-titlebar</link><generator>RSS for Node</generator><lastBuildDate>Wed, 06 May 2026 08:13:25 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/164490.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Mar 2026 10:48:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QFrame subclass with round corners and a custom titlebar on Thu, 26 Mar 2026 22:06:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/hskoglund">@<bdi>hskoglund</bdi></a> hey, thanks for the response. Not sure how that helps my situation though. I want round corners for the main window, not the sliders. I have already achieved that just through stylesheets. Didn't have to overlay two sliders.</p>
]]></description><link>https://forum.qt.io/post/837350</link><guid isPermaLink="true">https://forum.qt.io/post/837350</guid><dc:creator><![CDATA[anoban]]></dc:creator><pubDate>Thu, 26 Mar 2026 22:06:47 GMT</pubDate></item><item><title><![CDATA[Reply to QFrame subclass with round corners and a custom titlebar on Thu, 26 Mar 2026 11:04:59 GMT]]></title><description><![CDATA[<p dir="auto">Hi, some time ago I did a similar Qt app called ColorSliders <a href="https://gitlab.com/tungware/app/-/tree/main/ColorSliders" target="_blank" rel="noopener noreferrer nofollow ugc">https://gitlab.com/tungware/app/-/tree/main/ColorSliders</a>, in that one I overlay one slider with another.<br />
Screenshot:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/d8818616-6d81-4292-897a-100c1f46a29e.png" alt="Screenshot from 2026-03-26 12-04-32.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/837343</link><guid isPermaLink="true">https://forum.qt.io/post/837343</guid><dc:creator><![CDATA[hskoglund]]></dc:creator><pubDate>Thu, 26 Mar 2026 11:04:59 GMT</pubDate></item></channel></rss>