I'm trying to make volume button, on click it should mute/unmute and and on hover it should popup QSlider
, so user can set whatever level he wants. Now I'm trying to achieve this by showing slider window in enterEvent
and hiding it in leaveEvent
:
class VolumeButton(QToolButton):
def __init__(self, parent=None):
super().__init__(parent)
self.setIcon(volumeicon)
self.slider = QSlider()
self.slider.setWindowFlags(Qt.FramelessWindowHint)
self.slider.setWindowModality(Qt.NonModal)
def enterEvent(self, event):
self.slider.move(self.mapToGlobal(self.rect().topLeft()))
self.slider.show()
def leaveEvent(self, event):
self.slider.hide()
The problem is that mapToGlobal
seems to be connected in some way with enterEvent
and it creates recursion, but without mapToGlobal
I can't place slider at the right position.
I'm not sure that QToolButton
and FramelessWindow
are the right widgets to achieve wished result, so let me know if there a better ways to do that.