1
$\begingroup$

When I use the following line to add a number input:

row.prop(context.scene, 'output_size', text='Output size')

I get this result: number input

But my goal is to add "px" as a unit after the number like this: number input with px as unit

$\endgroup$

1 Answer 1

3
$\begingroup$

The output_size should be an IntProperty that is declared with a subtype set to "PIXEL".

bpy.props.IntProperty(subtype="PIXEL")

bl_info = {
    "name": "Subtype example",
    "author": "Robert Guetzkow",
    "version": (1, 0),
    "blender": (2, 80, 0),
    "location": "View3D > Sidebar > Example tab",
    "description": "Subtype example",
    "warning": "",
    "wiki_url": "",
    "category": "3D View"}

import bpy


class ExampleSettings(bpy.types.PropertyGroup):
    output_size: bpy.props.IntProperty(description="Some elaborate description", default=1024, subtype="PIXEL")


class EXAMPLE_PT_panel(bpy.types.Panel):
    bl_label = "Panel"
    bl_category = "Example tab"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"

    def draw(self, context):
        layout = self.layout
        layout.prop(context.scene.example_settings, "output_size", text="Output size")


classes = (ExampleSettings, EXAMPLE_PT_panel)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)
    bpy.types.Scene.example_settings = bpy.props.PointerProperty(type=ExampleSettings)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)
    del bpy.types.Scene.example_settings

if __name__ == "__main__":
    register()

Panel

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .