python - Mouse interaction issues on QSlider with QLabel overlay -
python - Mouse interaction issues on QSlider with QLabel overlay -
i pretty new qt/pyside , trying figure out way overlay qlabel
onto qslider
without loosing mouse events interactivity. using qstackedlayout
unable trigger them correctly label on top, , doesn't behave when under (the slider doesn't interpolate, jumps min max).
from pyside import qtcore, qtgui class customslider(qtgui.qwidget): def __init__(self, minval=0.0, maxval=1.0, default=0.0): super(customslider, self).__init__() self.slider = qtgui.qslider() self.slider.setrange(0.0, 1.0) self.slider.setorientation(qtcore.qt.horizontal) self.slider.setstylesheet(""" qslider::groove:horizontal { background: black; height: 40px; } qslider::sub-page:horizontal { background: grey; height: 40px; } qslider::add-page:horizontal { background: black; height: 40px; }""") self.overlay = qtgui.qlabel() self.overlay.settext("label") self.overlay.setalignment(qtcore.qt.alignhcenter | qtcore.qt.alignvcenter) self.overlay.setstylesheet("""qlabel{font: bold 18px;}""") self.layout = qtgui.qstackedlayout() self.layout.setstackingmode(qtgui.qstackedlayout.stackall) self.layout.addwidget(self.slider) self.layout.addwidget(self.overlay) self.setlayout(self.layout)
any suggestions more welcome.
regards
the slider jumps 0 1 because accepts integer values. if, example, set maximum 100, you'll find works.
as stacking, can pass events through:
class customslider(qtgui.qwidget): def __init__(self, minval=0.0, maxval=1.0, default=0.0): super(customslider, self).__init__() self.slider = qtgui.qslider() self.slider.setrange(0.0, 100.0) # <-- self.slider.setorientation(qtcore.qt.horizontal) self.slider.setstylesheet(""" qslider::groove:horizontal { background: black; height: 40px; } qslider::sub-page:horizontal { background: grey; height: 40px; } qslider::add-page:horizontal { background: black; height: 40px; }""") self.overlay = qtgui.qlabel() self.overlay.settext("label") self.overlay.setalignment(qtcore.qt.alignhcenter | qtcore.qt.alignvcenter) self.overlay.setstylesheet("""qlabel{font: bold 18px;color:red;}""") self.overlay.mousepressevent = self.slider.mousepressevent # <-- self.overlay.mousereleaseevent = self.slider.mousereleaseevent # <-- self.layout = qtgui.qstackedlayout() self.layout.setstackingmode(qtgui.qstackedlayout.stackall) self.layout.addwidget(self.slider) self.layout.addwidget(self.overlay) self.setlayout(self.layout)
python qt overlay pyside
Comments
Post a Comment