I have a QDial
widget and I'm wondering if there is a way to disable mouse clicks on the dial. I only want to be able to set the value of the QDial by using setValue()
. When a user clicks on the dial, I want nothing to happen instead of moving to the spot where the user clicked. I have looked into mousePressEvent
handler, but it still moves the needle to a new location. How can I disable mouse clicks from affecting the value of the QDial? Also: is there a way to change the current value indicator (circle object) into a needle through stylesheets?
from PyQt4 import QtGui, QtCore
class DisabledDial(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.dial = QtGui.QDial()
self.dial.setMaximum(360)
self.dial.setNotchesVisible(True)
self.dial.setWrapping(True)
self.layout = QtGui.QVBoxLayout()
self.layout.addWidget(self.dial)
self.setLayout(self.layout)
self.timer = QtCore.QTimer()
self.timer.timeout.connect(self.tick_update)
self.timer.start(1000)
def tick_update(self):
self.dial.setValue(self.dial.value() + 10)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
dial = DisabledDial()
dial.show()
sys.exit(app.exec_())