使用颜色标签复制 Maya QLineEdits
Replicating Maya QLineEdits with the color labels
我正在尝试使用我们在 Maya 中看到的那些创建/复制 QLineEdit 小部件(它在左侧有一个颜色标签,表示它是否已设置键控)
我可以在一定程度上复制它,但同时遇到一些问题:
- 见附件,我的图标和QLineEdit最左外边之间有一个小缝隙
- 尽管实际图像按 10x16 像素缩放,但图标大小并非我预期的矩形大小。
这是我的 QLineEdit 的快速代码示例:
my_icon = QtGui.QPixmap('full_keyed.png')
self.ui.positionXLineEdit.addAction(my_icon, QtWidgets.QLineEdit.LeadingPosition)
那么,有没有更好的办法让我实现我在 Maya 中看到的想要实现的目标?
通过使用 widgetHierarchy.py you can find out that those "keyed" fields in the ChannelBox are part of a QTableView, and are therefore QStyledItemDelegates.
恐怕我没有使用这些的个人经验,但经过一些挖掘后,看起来那些 QStyledItemDelegates 是您想要为控件建模的对象。查看查询 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>}
第一行表示 "Translate X" 标签的项目数据,第二行填写实际输入字段和 "keyed" 标记。
其实我找到了方法
另外,我应该提到我的小部件是使用 Qt 设计器创建的,因此,使用 QStyledItemDelegate
对我来说可能不是理想的解决方案。
这就是我目前在 GUI 中实现 'color-coding' 功能的方式:
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}
"""
我正在尝试使用我们在 Maya 中看到的那些创建/复制 QLineEdit 小部件(它在左侧有一个颜色标签,表示它是否已设置键控)
我可以在一定程度上复制它,但同时遇到一些问题:
- 见附件,我的图标和QLineEdit最左外边之间有一个小缝隙
- 尽管实际图像按 10x16 像素缩放,但图标大小并非我预期的矩形大小。
这是我的 QLineEdit 的快速代码示例:
my_icon = QtGui.QPixmap('full_keyed.png')
self.ui.positionXLineEdit.addAction(my_icon, QtWidgets.QLineEdit.LeadingPosition)
那么,有没有更好的办法让我实现我在 Maya 中看到的想要实现的目标?
通过使用 widgetHierarchy.py you can find out that those "keyed" fields in the ChannelBox are part of a QTableView, and are therefore QStyledItemDelegates.
恐怕我没有使用这些的个人经验,但经过一些挖掘后,看起来那些 QStyledItemDelegates 是您想要为控件建模的对象。查看查询 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>}
第一行表示 "Translate X" 标签的项目数据,第二行填写实际输入字段和 "keyed" 标记。
其实我找到了方法
另外,我应该提到我的小部件是使用 Qt 设计器创建的,因此,使用 QStyledItemDelegate
对我来说可能不是理想的解决方案。
这就是我目前在 GUI 中实现 'color-coding' 功能的方式:
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}
"""