简体   繁体   中英

How to enable drag selection in UI Maya Python

I would like to know how to enable drag selection to select some buttons on my UI.

I have tried to use cmds.selectPref(clickBoxSize=True) but it doesn't work.

import maya.cmds as cmds
import shiboken
import maya.OpenMayaUI as omUI
from PySide import QtGui, QtCore
ui_btns = {}

win = cmds.window()
cmds.columnLayout(adjustableColumn=True)
ui_btns["btn_a"] = cmds.button(label="Burning")
ui_btns["btn_b"] = cmds.button(label="Man")
cmds.setParent("..")
cmds.showWindow(win)

draggerContext_id = "dga"
def dga():
    cp = QtGui.QCursor().pos()
    widget = QtGui.qApp.widgetAt(cp)
    ui_id = omUI.MQtUtil.fullName(long(shiboken.getCppPointer(widget)[0]))
    print "ui path :{0}".format([ui_id for k, v in ui_btns.iteritems() if ui_id in v])

cmds.draggerContext(draggerContext_id, dragCommand = "dga()", cursor="hand", space="screen")
cmds.setToolTo(draggerContext_id)

its a simple idea to get the ui path, you can also replace the draggerContext with a scriptjob or the threading.Timer().start() command, there are more solutions, depend on your UI and the workflow (post process eval or ui element dragcallback...it would be great to see some sections from your code)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM