A slider property that acts like an operator

I am interested in having a slider property, that will be able to be used like an operator.

As for example in this scenario:

  • I want to change the X position of the cube.
  • I change the slider value and see the position change immediately.
  • Once I release the click from the slider the cube stays in the same place. However the slider property gets back to zero.

Does that give you any ideas for hacks or alternative better ways?

last request not certain it can be done!

but easy to move a cube with a prop slider in a panel

note: this should be in python forum

happy bl

https://docs.blender.org/api/current/bpy.props.html
look at Update example, and Getter/Setter example.
I’m not sure it will completely solve what you want, but it can help you a bit.

What you explain in you example look a lot at how blender transforms objects, you have the value offset appearing in the UI , you can enter value here ect…
I’m not sure it’s worth the effort of implementing similar functionnality but in a far more hackish way. But maybe for other cases it can help…

Good one, I tried the update example but it resulted to infinite recursion. So the other way works better.

import bpy

class OBJECT_PT_property_example(bpy.types.Panel):
    bl_idname = "object_PT_property_example"
    bl_label = "Property Example"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    bl_category = "Tool"

    def draw(self, context):
        row = self.layout.row()
        row.prop(context.scene, "slider_update")

def update_slider_callback(self, value):
    c = bpy.context.object
    c.location.x = value
    print(c.location.x, value)
    
try:
    bpy.utils.unregister_class(OBJECT_PT_property_example)
    del bpy.types.Scene.slider_start
    del bpy.types.Scene.slider_update
except:
    pass

bpy.types.Scene.slider_update = bpy.props.FloatProperty(name="Slider Update", set=update_slider_callback)
bpy.utils.register_class(OBJECT_PT_property_example)    

There is also a bug occurring with the position, because the cube gets reset back to 0 each time. This would be better fixed by getting the exact position at first and then combine it with current property value. But I will think about this one.