Hi all, I need some insights on this gui signals + undo.
In my tool, there is a QLineEdit and a QSlider in which both are connected/ linked to each other, where if you made changes in the QLineEdit, it will updates the QSlider, likewise if you made changes on the QSlider, it will updates the values in the QLineEdit.
Currently I am having issues with QSlider where I am trying to collate the actions (as User slides it) as 1 undo action.
Here is my code:
# The signal for the slider
self.ui.planeSizeHorizontalSlider.valueChanged.connect(self.plane_size_slider)
def plane_size_slider(self, value):
img_plane_node = self.get_current_img_plane()
value /= 10.00
self.ui.planeSizeLineEdit.setText(str(value))
self.set_plane_size(img_plane_node, value)
def set_plane_size(self, node, value):
width = cmds.getAttr("{0}.width".format(node))
height = cmds.getAttr("{0}.height".format(node))
ratio = height / width
with UndoManager(): # UndoManager is a contextmanager
cmds.setAttr("{0}.maintainRatio".format(node), 0)
cmds.setAttr("{0}.width".format(node), value)
cmds.setAttr("{0}.height".format(node), value * ratio)
cmds.setAttr("{0}.maintainRatio".format(node), 1)
While in viewport, the imagePlane does gets scaled accordingly as I perform changes on the slider for visual purposes, but when it comes to undo, it seems to be to factoring into account of all the values that I have made (eg. the slider value was initially at 0 and I slide it to 10, and so 10 actions/ undos)
My question here is, if there are ways in which I can tell my QSlider to:
- still uses valueChanged (so that User can still visualize the scaling)
- but collate the āslidingā as one action/ undo instead?
I tried using sliderReleased
but it only seems to scale the item after it has been released and it is pretty much giving me the same results as without the use of it.
Any insights?