Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Maya shortcut toggle
Qt 6.11 is out! See what's new in the release blog

Maya shortcut toggle

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 576 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Geuse
    wrote on last edited by
    #1

    Hi everybody. I'm trying to create a shortcut that acts as a toggle so I want the KeyPress and KeyRelease to be implemented and run two opposite commands. In this case opening and closing the shelf.

    I've tried a few different ways, without any luck. Tried making my own class, inherited from QtWidgets.QShortcut and implementing eventfilter, but seems I don't know what I'm doing.

    For reference, this code works, but it doesn't toggle the way I want.

    import pymel.core as pm
    import maya.mel as mel
    from functools import partial
    from maya import OpenMayaUI as omui
    from PySide2 import QtWidgets, QtGui, QtCore
    from shiboken2 import wrapInstance
    
    def getMainMayaWindow():
        mayaMainWindowPtr = omui.MQtUtil.mainWindow()
        mayaMainWindow = wrapInstance(int(mayaMainWindowPtr), QWidget)
        return mayaMainWindow
    
    def shelfHeightToggle():
        gShelfTopLevel = mel.eval('$tmpVar=$gShelfTopLevel')
        value = pm.shelfTabLayout(gShelfTopLevel, q=1, h=1)
        if value == 64:
            value = 94
        else:
            value = 64
    
        pm.shelfTabLayout(gShelfTopLevel, e=1, h=value)
    
    shelfHeightShortcut = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_section), getMainMayaWindow())
    shelfHeightShortcut.setContext(QtCore.Qt.ApplicationShortcut)
    shelfHeightShortcut.activated.connect(partial(shelfHeightToggle))
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Why not use a toggle action as target of your shortcut ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Why not use a toggle action as target of your shortcut ?

        G Offline
        G Offline
        Geuse
        wrote on last edited by
        #3

        @SGaist Thank you. I'm not at all familiar with a toggle action so I will see what I can read about it.
        With that said. I managed to get it working with creating a class with an event filter method with KeyPress and KeyRelease. But I'm very new so I don't know anything about the best practices.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The checked property is what you are looking for.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved