0

I am trying to create/ replicate a QLineEdit widget with the ones that we see in Maya (where it has a color label on the left hand side that denotes if it is keyed or not)

I am able to replicate it to a certain extent, however having some issues at the same time:

  • See attached, between my icon and the left outer-most of the QLineEdit, there is a small gap
  • The icon size is not rectangular-ish as I would have expected despite the actual image is scaled in 10x16 pixels.

Here is a quick code sample of my QLineEdit:

my_icon = QtGui.QPixmap('full_keyed.png')
self.ui.positionXLineEdit.addAction(my_icon, QtWidgets.QLineEdit.LeadingPosition)

And so, is there a better for me to attain what I had wanted to achieve as seen in Maya?

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
yan
  • 631
  • 9
  • 30

2 Answers2

2

By using widgetHierarchy.py you can find out that those "keyed" fields in the ChannelBox are part of a QTableView, and are therefore QStyledItemDelegates.

I'm afraid I don't have personal experience working with those, but after a little digging it looks like those QStyledItemDelegates are what you want to model your controls after. Take a look at what prints out when querying the QStyledItemDelegates itemData():

{0: u'Translate X', 2: u'Translate X', 3: u'Translate X', 6: <PySide2.QtGui.QFont( "smallPlainLabelFont,12,-1,5,50,0,0,0,0,0" )  at 0x7f8d2070ab48>, 7: 66, 8: <PySide2.QtGui.QBrush(QColor(ARGB 1, 0.266667, 0.266667, 0.266667),SolidPattern)  at 0x7f8d2070ab00>, 9: <PySide2.QtGui.QBrush(QColor(ARGB 1, 0.733333, 0.733333, 0.733333),SolidPattern)  at 0x7f8d2070ac68>}
{0: u'0 ', 2: u'0 ', 3: u'0 \n\nKeyed On Frame', 6: <PySide2.QtGui.QFont( "smallPlainLabelFont,12,-1,5,50,0,0,0,0,0" )  at 0x7f8d2070ac68>, 7: 65, 8: <PySide2.QtGui.QBrush(QColor(ARGB 1, 0.803922, 0.152941, 0.160784),SolidPattern)  at 0x7f8d2070ab48>, 9: <PySide2.QtGui.QBrush(QColor(ARGB 1, 0, 0, 0.00784314),SolidPattern)  at 0x7f8d2070a3f8>}

ChannelBox Exmaple

The first line represents the itemData for the "Translate X" label and the second line fills out the actual input field AND the "keyed" marker.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
0

I have actually found a method.

Adding on, I should have mentioned that my widgets are created using the Qt Designers and so, the use of QStyledItemDelegate may not be the ideal solution for me.

This is how I currently implemented the 'color-coding' features into my GUI:

def set_color_labelling(self):
    # There is a method I have written to check if the said attribute has any
    # keys to begin with.

    # `color_val` are as follows:
    # solid red - If it is keyed and current time is on the actual key
    # solid pink - If it is keyed but current time is not on any of the keys
    # none - If the attribute has no keys at all
    color_val = check_for_keys()

    lineedit_stylesheet = """QLineEdit{{
        border:0px; border-left: 5px {0}; padding-left: 3px}}
    """.format(color_val)

    # However for non-animated channels, the stylesheet context will be slightly
    # different. This is so that the offset/ spaces for numbering will remains
    # at the same position as when it is animated. If not, the positioning will
    # be towards the left hand border.
    if color_val == "none":
        lineedit_stylesheet = """QLineEdit{
            border-left: 5px none; padding-left: 8px}
        """
yan
  • 631
  • 9
  • 30