<?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[Custom drawn QSlider]]></title><description><![CDATA[<p dir="auto">I'm working on porting an app from MFC to Qt. One of the main controls in our app is a custom drawn CSliderCtrl. It has a bunch of custom functionality that the standard slider can not duplicate, but we use  slider as the base class because at it's core it's just a thumb that slides back and forth along a track.</p>
<p dir="auto">Does anyone know of any examples or tutorials for creating custom controls in Qt? This is the slider I need to recreate...</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/77e38f33-d7ad-4123-86db-f1fb834439d2.png" alt="7baed6b9-9fcd-470d-8514-637d9cf0a90c-image.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">As you can see it has a multi color track, a custom thumb and special markers that can be added along the rack. (these are not ticks and can be anywhere along the track)</p>
]]></description><link>https://forum.qt.io/topic/123385/custom-drawn-qslider</link><generator>RSS for Node</generator><lastBuildDate>Tue, 10 Nov 2026 05:52:48 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/123385.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 02 Feb 2021 21:59:37 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Custom drawn QSlider on Tue, 02 Feb 2021 22:55:38 GMT]]></title><description><![CDATA[<p dir="auto">Forgot, here's a screenshot:<br />
<img src="https://ddgobkiprc33d.cloudfront.net/3c46d25d-111c-4dc7-92c4-b72916391214.png" alt="CustomSliders.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/642037</link><guid isPermaLink="true">https://forum.qt.io/post/642037</guid><dc:creator><![CDATA[hskoglund]]></dc:creator><pubDate>Tue, 02 Feb 2021 22:55:38 GMT</pubDate></item><item><title><![CDATA[Reply to Custom drawn QSlider on Tue, 02 Feb 2021 22:49:22 GMT]]></title><description><![CDATA[<p dir="auto">Hi, for a project a needed a QSlider that looked like a slider on a musician's mixer table, here's the code I used:</p>
<pre><code>void  MainWindow::customizeSlider(QWidget* pSlider, QColor c, int nWidthInPixels, int nHeightInPixels)
{
    static int nnBorderWidth  = 1;
    static int nnBorderRadius = 7;  // for nice rounded corners
    static QColor ccBorder("grey");
    static int nnLineWidth    = 2;
    static int nnMidLineWidth = 0;

// will the real QSlider* please stand up (use a safe downcast)
    QSlider* pRealSlider = dynamic_cast&lt;QSlider*&gt;(pSlider);
    if (nullptr == pRealSlider)
        return; // no QSlider* present, so skip this

// construct and set the style sheet (2 parts, one for the groove and one for the handle)
    pRealSlider-&gt;setStyleSheet(QString(
        ".QSlider::groove { background: transparent; height: %1px; } "
        ".QSlider::handle { background: %2; border-radius: %3px; border: %4px solid %5; width: %6px;}")
        .arg(nHeightInPixels).arg(c.name()).arg(nnBorderRadius).arg(nnBorderWidth).arg(ccBorder.name()).arg(nWidthInPixels));

// need to recreate the QSlider's groove? (the original is now invisible due to the stylesheet applied above)
    QString sFrameObjectName = pRealSlider-&gt;objectName() + "Frame";  // we'll be using a QFrame
    if (nullptr == pRealSlider-&gt;parentWidget()-&gt;findChild&lt;QFrame*&gt;(sFrameObjectName))
    {
    // yes, so wire up a new QFrame to act as a surrogate groove, use the same parent and geometry as the slider
        QFrame* pFrame = new QFrame(pRealSlider-&gt;parentWidget());
        pFrame-&gt;setGeometry(pRealSlider-&gt;geometry());
        pFrame-&gt;setObjectName(sFrameObjectName);
        pFrame-&gt;setFrameStyle(((Qt::Horizontal == pRealSlider-&gt;orientation()) ? QFrame::HLine : QFrame::VLine) | QFrame::Sunken);
        pFrame-&gt;setLineWidth(nnLineWidth);
        pFrame-&gt;setMidLineWidth(nnMidLineWidth);

    // finally, change the z-order so that our custom groove is drawn under the handle (just like the real groove)
        pFrame-&gt;stackUnder(pRealSlider);
    }
}
</code></pre>
<p dir="auto">This code might help you create the custom thumb and the special markers, and even the multiple colors, you can try applying them where I create the groove above. Good luck!</p>
]]></description><link>https://forum.qt.io/post/642036</link><guid isPermaLink="true">https://forum.qt.io/post/642036</guid><dc:creator><![CDATA[hskoglund]]></dc:creator><pubDate>Tue, 02 Feb 2021 22:49:22 GMT</pubDate></item><item><title><![CDATA[Reply to Custom drawn QSlider on Tue, 02 Feb 2021 22:13:10 GMT]]></title><description><![CDATA[<p dir="auto">I can't offer any ready made tutorial but there's not much to it really.<br />
Depending on how low level you need to go subclass either <code>QSlider</code> or the base <code>QAbstractSlider</code>.<br />
Paint your custom markers in the overriden <code>paintEvent</code> using <code>QPainter</code>.<br />
Handle adding, moving and removing custom markers in mouse related event overrides: <code>mousePressEvent</code>, <code>mouseReleaseEvent</code> and <code>mouseMoveEvent</code>.</p>
]]></description><link>https://forum.qt.io/post/642031</link><guid isPermaLink="true">https://forum.qt.io/post/642031</guid><dc:creator><![CDATA[Chris Kawa]]></dc:creator><pubDate>Tue, 02 Feb 2021 22:13:10 GMT</pubDate></item></channel></rss>