Labels

A couple of classes are available which are derived from QtWidgets.QLabel and provide specialized functionality.

Class Inheritance

UI4.Widgets.AttributeDropLabel

class UI4.Widgets.AttributeDropLabel

Bases: PyQt5.QtWidgets.QLabel

Class implementing a label that accepts attributes that have been dragged from the Attributes tab.

When data of required formats is provided in the MIME data of the dragged object, an instance of this class emits one or two of the following Qt signals, to which slots can be connected using standard Qt code:

  • 'attrDropped'
  • 'attrDroppedWithScenegraphPath'

The above signals are only emitted when data of the following MIME data formats has been provided in the dragged object:

  • attribute/attr – Python code that can be executed to obtain an object that represents the dragged attribute
  • attribute/name – the name of the dragged attribute

In addition to the above formats, the following formats are also supported:

  • attribute/hints – a string representation of widget hints that were used for the widget from which the drag was started
  • attribute/scenegraphpath – the path of a scene graph location that contained the dragged attribute

Example Screenshot:

Screenshot of an AttributeDropLabel widget

__init__(parent)

Initializes an instance of the class.

The text of the label is hard-coded to Drop Attributes Here, the label is configured to accept drops, and its alignment is set to horizontally and vertically center the text inside of the label’s bounds.

Parameters:parent (QtWidgets.QWidget or None) – The parent widget to own the new instance. Passed verbatim to the base class initializer.
attrDropped
attrDroppedWithScenegraphPath
dragEnterEvent(event)

Event handler for widget drag enter events which are passed in the event parameter. Is called when a drag is in progress and the pointer enters the widget.

If the event is ignored, the widget won’t receive any drag move events.

The implementation in this class accepts the given event if the required MIME data is provided.

Parameters:event (QtGui.QDragEnterEvent) – The object that describes the event.
dropEvent(event)

Event handler for widget drop events which are passed in the event parameter. Is called when the drag is dropped on the widget.

The implementation in this class checks if the required MIME data is provided in the given event, and if so, evaluates the Python code given in the attribute/attr format to obtain the dragged attribute, as well as any widget hints that may be provided in the attribute/hints format, and emits the 'attrDropped' signal with the dragged attribute, its name as taken from data of the attribute/name format, and the decoded hints dictionary.

If data of the attribute/scenegraphpath format is provided as well, the function emits the 'attrDroppedWithScenegraphPath' signal with the dragged attribute, the attribute name, widget hints, and the path of the scene graph location that contained the dragged attribute.

Parameters:event (QtGui.QDropEvent) – The object that describes the event.