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

python
maya

#1

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


#2

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


#3

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


#4

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.


#5

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


#6

@R.White, 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.


#7

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?


#8

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.


#9

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.


#10

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 https://github.com/theodox/mGui/ which is a wrapper that @Theodox and I collaborate on. Helps take a lot of the mess and ick out of using cmds.


#11

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.


#12

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.


#13

@R.White, 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.


#14

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


#15

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


#16

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.


#17

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…


#18

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!