Qt Custom Tags Widget

A platform-independent QWidget to display tags written in Python/Pyside2.
The widget adapts to the QApplication style palette.

The need for this came from another Qt application that needed a tags display but Qt by default does not have anything like it and it needed to work with PySide2 in Maya.
Another requirement was, the styling needed to pick up the palette from any application the widget is a child of.
Currently tags can be added and removed. No duplicates are allowed and it is using a custom layout method to make the widget responsive to its parent container size.

Appearance on Windows in a standalone QApplication.
Appearence in Maya.

Short video showing the adding and removing of widget as well as resizing the container.

Here is the code. It is still very work in progress. These are a few features and improvements I’d like to add in the future:

  • Size Hint improvements
  • Drag and Drop re-ordering
  • Priority based on ordering
  • Tight packed layout as alternative to fixed order layout
  • Explore applicability of MVVM pattern
  • Better styling possibilities

The imports. There is nothing special going on here. I could have used the Qt.py but since I am not actively using PyQt4 or PySide anywhere I didn’t see the need for that.

The NQTagsView class that creates and manages the individual tags as well as the layout. This class is the one that would be added to a Qt application or window layout.

On Windows with font size set to 16

Here we have the NQTagWidget class. This is taking care of the drawing of the tag itself and is currently using a color scheme based on the QApplication Style Palette.
Some of the painting get’s a little bit unwieldy trying to stay responsive to the font size and spacing.