message = QtGui.QPlainTextEdit()
slider = QtGui.QSlider()
def slider_func():
if slider.value() == 0:
\'\'\'what to write here ?\'\'\'
if slider.value
Here is an example of how to watch the value of the slider, and modify a QPlainText
when the value is at certain values.
from PyQt4.QtGui import *
from PyQt4.Qt import *
import sys
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
layout = QVBoxLayout()
self.setLayout(layout)
self.text = "Please enter some text"
self.edit = QPlainTextEdit(self.text)
layout.addWidget(self.edit)
slider = QSlider(Qt.Horizontal)
layout.addWidget(slider)
slider.valueChanged.connect(self.change_value)
def change_value(self, value):
if value == 0:
self.edit.setPlainText(self.text)
elif value == 1:
self.edit.setPlainText(self.text[::-1])
elif value > 1:
self.edit.setPlainText("Slider value is above 1, value: {0}".format(value))
app = QApplication(sys.argv)
win = Window()
win.show()
sys.exit(app.exec_())
When the QSlider.valueChanged
signal is emitted, the new value is carried with it. So in my slot Window.change_value(self, value)
the value
positional argument will always contain the new QSlider
value; which allows you to test against it.