Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize QDial with stylesheet

There are comprehensive examples for style sheets of QWidgets here. Unfortunately QDial is missing from the examples.

Can I change the appearance (basically the color, border of the rotary knob) just by a stylesheet? In this article a new dial class is supporting style sheets, but can it not be done with Qt's standard class?

The slider / scrollbar examples show how every detail can be tweaked, so I wonder if there is something similar for QDial? I understand I can exchange the underlying image, but would prefer an easy way just to set its color, border.

I have tried the standard attributes such as backgroud-color, background, color with no success. Also tried QDial::handle , so a hint would be useful.

like image 361
Horst Walter Avatar asked Oct 21 '22 17:10

Horst Walter


1 Answers

You can change the background with style sheets but that appears to be it.

Perhaps things have changed since you asked the question on Jan 6, 2014 but I was able to get style sheets to work for the background only. Everything else I tried had no effect.

Notice how the background change affects the needle too.

The QDial widget rendered in FC20 under MATE using the giving stylesheet

from PyQt4 import QtGui, QtCore
import os
import time

class MyDial(QtGui.QDial):
    style =''' 
    QDial
    {
        background-color:QLinearGradient( 
            x1: 0.177, y1: 0.004, x2: 0.831, y2: 0.911, 
            stop: 0 white, 
            stop: 0.061 white, 
            stop: 0.066 lightgray, 
            stop: 0.5 #242424, 
            stop: 0.505 #000000,
            stop: 0.827 #040404,
            stop: 0.966 #292929,
            stop: 0.983 #2e2e2e
        );
    }
    '''
    def __init__(self, parent=None):
        super(MyDial, self).__init__(parent)

        self.setStyleSheet(self.style)

        self.setRange(0,100)
        self.setValue(0)
        self.setWrapping(True) # Smooth transition from 99 to 0
        self.setNotchesVisible(True)
like image 100
shrewmouse Avatar answered Nov 15 '22 10:11

shrewmouse