Hello everyone, I have a little problem with the PySide QSlider. I'm trying to draw text on the ticks of my QSlider. I saw that we could use "sliderValueFromPosition" to find the position but impossible to make it work correctly ... It always returns 0. I'll show you my code.
def __range_to_pos(self, value): qt_options = QtGui.QStyleOptionSlider() self.initStyleOption(qt_options) style = QtGui.QApplication.style() gr = style.subControlRect(style.CC_Slider, qt_options, style. SC_SliderGroove, self) sr = style.subControlRect(style.CC_Slider, qt_options, style. SC_SliderHandle, self) if self.orientation() == QtCore.Qt.Horizontal: slider_length = sr.width() slider_min = gr.x() slider_max = gr.right() - slider_length + 1 else: slider_length = sr.height() slider_min = gr.y() slider_max = gr.bottom() - slider_length + 1 return style.sliderValueFromPosition( self.minimum(), self.maximum(), value, slider_max - slider_min, qt_options.upsideDown ) I made an alternative but I have a small lag on my offset. def __range_to_pos(self, value): i_percent_interval = 100.0 / (self.maximum() - 1.0) # Size from orientation if self.orientation() == QtCore.Qt.Horizontal: f_size = self.rect().width() else: f_size = self.rect().height() # Calculate offset qt_font_metric = QtGui.QPainter(self).fontMetrics() f_text_size = float(qt_font_metric.width(str(value))) i_percent_offset = (f_text_size / f_size) * 100.0 f_offset = f_size / 100.0 * i_percent_offset if value == 0: f_offset = 0.0 elif value != self.maximum() - 1: f_offset /= 2.0 # Position x_pos = f_size / 100.0 * (i_percent_interval * value) if self.orientation() == QtCore.Qt.Horizontal: qt_pos = QtCore.QPoint(x_pos - f_offset, self.rect().bottom()) else: qt_pos = QtCore.QPoint(self.rect().bottom(), x_pos - f_offset) return qt_pos I find it a pity not to be able to operate the command of PySide. Does anyone know the solution? -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/9e2f012c-0fad-4687-81e6-d6561c2bdfed%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.