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)
QDial
不支持样式表(这里有一个旧的错误报告 https://bugreports.qt-project.org/browse/QTBUG-1160)。但是可以通过自定义QStyle
进行自定义。查看新的 Fusion 样式下QDial
的外观。 - Oleg Shparber