Is there anyway to query if the scroll bar is visible on the shelf in Mel?

Is there anyway to query if the scroll bar is visible on the shelf in Mel?

malcolm_341
Collaborator Collaborator
682 Views
2 Replies
Message 1 of 3

Is there anyway to query if the scroll bar is visible on the shelf in Mel?

malcolm_341
Collaborator
Collaborator

I'm looking for a way to query the active shelf tab and see if the scroll bar is active/visible, is that possible in Mel?

0 Likes
Accepted solutions (1)
683 Views
2 Replies
Replies (2)
Message 2 of 3

FirespriteNate
Advocate
Advocate
Accepted solution

I don't think there is any way in vanilla MEL to query that information. ShelfLayouts are a custom compound control type, so the only things you can really query are the parameters exposed to the `shelfLayout` command. If it was a regular `scrollLayout` you could make an informed guess that the scrollBar was visible by querying the width of the scrollLayout and the width of it's child layout and comparing the two to see how much difference there was, but I'm not even sure that's guaranteed to work 100%.

 

You can, however, do this relatively trivially in Python, by querying the underlying Qt Widgets, but it does get quite involved if you're not familiar with Python/Qt/Maya API 😅

But if you did want to stray away from the comfort of MEL, it is possible, for example (tested on Maya 2023, probably won't work on 2025 without editing, as that uses PySide6):

 

from maya import mel
from maya import cmds
from maya.OpenMayaUI import MQtUtil
from PySide2.QtWidgets import QWidget
from shiboken2 import wrapInstance

def isCurrentShelfScrollbarVisible():
    """Returns True if the scrollbar is visible on the CURRENT shelf."""
    # get the main Shelf Layout using MEL vars
    layout = mel.eval("string $nul = $gShelfTopLevel;")
    # get the current shelf
    shelf = cmds.shelfTabLayout(layout, q=True, selectTab=True)
    # get the pointer to the control object
    ctrlPtr = MQtUtil.findControl(shelf)
    # wrap it into a literal QWidget
    wrapInstance(int(ctrlPtr), QWidget)
    # Get the widget's children (we're looking for QScrollArea)
    childWidgets = widget.children()
    # the QScrollArea is the second item (really we should check this)
    scroll = childWidgets[1]
    # return whether it's verical scrollbar is visible or not
    return scroll.verticalScrollBar().isVisible()

 

 and you could then call this from MEL like so:

 

int $shelfScrollbarVis = `python("isCurrentShelfScrollbarVisible()")`;

 

Message 3 of 3

malcolm_341
Collaborator
Collaborator

@FirespriteNateThanks for your reply, I'm not ready to leave the comfort of Mel yet, I enjoy it too much. While I wasn't able to find out if the scroll bar is visible my wife was able to help me with the math and we figured out another way to do what I wanted which was scale the shelf vertically to fit all the rows of buttons that went off screen if your shelf has more icons than fit into the current shelf height.

 

This was accomplished using The following commands

layout -q -cellHeight ShelfLayout;

layout -q -cellWidth ShelfLayout;

layout -q -numberOfChildren ShelfLayout;

layout -q -width ShelfLayout;

layout -q -height ShelfLayout;

 

Rounding up the shelf height and then figuring out how much to grow the shelf by based on the above info.