[Maya][Python] Spinbox using maya.cmds?

Hi, is there a way of creating a spinbox without using QT?

I don’t believe so. All the built int stuff seems to favor sliders over spin boxes.

Easier way to add it using QT? I mean without knowing API , OOP and other stuff?

Probably the absolute simplest would be generating your UI in the designer and then loading it with cmds.loadUI. As it can be a little tricky to parent QWidgets under random maya controls.

Don’t think there is. However if you set the -step flag on an intfield, the user can middle-drag in that field to increment or decrement the value by the step you set

@bob.w, But this way spinbox won’t be imported , will it?

@Theodox, yeah, thanks for the tip. At least this is much better than typing in.

https://www.highend3d.com/maya/tutorials/scripting/mel/c/using-qt-designer-for-mel-interfaces

found a tutorial teaching how to do it with loadUI. Now only thing left is to figure out how to connect the commands.

Also, what is the advantage of using PyQT or PySide over just importing the UI file?

More granular control usually. I tend to avoid Qt unless no other option presents itself, but usually when I’m at that point I tend to be using it in a pretty focused manner and it usually makes more sense to just handle all the parts myself.

Isn’t QT more intuitive than coding the UI inside Maya? Half the time it’s a guessing game building the UI and figuring out the correct sizes and layouts for everything inside Maya, at least for me.

A core advantage of using the builtin commands is forward compatibility. Plus Qt happens to bring a lot of complexity to the table.

Though I will admit that I don’t often work with cmds directly, instead I use GitHub - theodox/mGui: Python module for cleaner maya GUI layout syntax which is a wrapper that @Theodox and I collaborate on. Helps take a lot of the mess and ick out of using cmds.

1 Like

The main draw of Pyside in Maya is flexibility. There is a pretty steep learning curve and there are some headaches that come with newer versions (such as the PySide to PySide2 change between 2016 and 2017).

But since I started learning PyQt in Maya 2013 I haven’t looked back.

Now it’s much clearer.

Thank you all for information. I’ll guess I’ll stick with cmds for now, and slowly learn QT on the side.

@bob.w, this could be knocked up in mGui with two IconTextButtons :slight_smile:

I’ve been debating doing some common compound controls for 2.3 or later, maybe this would be a good test case.

Oh that is wonderfully evil, if I could get Maya to stop turning my and into ? could even do it without the IconTextButtons.

At work I distribute Glyphicons but reading the license it doesn’t seem like we could do that. However if we found a good small set of OS icons we could bundle them

I’ve used http://fontawesome.io/ in the past for some web work. It looks like some kind soul has done the legwork of converting the fonts to svg - png files.

That looks good , though we’ll have to make sure that it’s not going to change the MGui license to GPL – that will exclude a lot of places on principle.

Here’s a fun thing to think about – what’s the most elegant way to make a compound widget feel like a regular widget to other code? This would make a spinbox:

    with HorizontalStretchForm(key="IntSpinner#") as root:
        field = IntField(width = 256, height = 24)
        with VerticalStretchForm(width = 24) as box:
            up = IconTextButton(height = 12, style='iconOnly', image='up')
            down = IconTextButton(height = 12,style='iconOnly', image='up')

but you’d like to be able to do

  sometihing = IntSpinner()
  something.value = 4

I think we’d need to create a property accessor that knows how to grab a sub-control’s properties, just not sure the most minimalist way to do it…

Oh, in case anyone is actually interested in our craziness. I’ve moved the discussion over to github.

Other folks are more than welcome to join in!

1 Like