Repository: napari/napari

Issue:
[Qt6] AttributeError when renaming a layer
## 🐛 Bug

This seems to be yet another small Qt6 issue related to enum name changes.

## To Reproduce

Steps to reproduce the behavior:

1. Launch napari from a Qt6 environment
2. Open a file or otherwise create a new layer
3. Double click the layer to rename it, triggering the exception

```
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/src/napari/napari/_qt/containers/_layer_delegate.py:141, in LayerDelegate.createEditor(self=<napari._qt.containers._layer_delegate.LayerDelegate object>, parent=<PyQt6.QtWidgets.QWidget object>, option=<PyQt6.QtWidgets.QStyleOptionViewItem object>, index=<PyQt6.QtCore.QModelIndex object>)
    138 editor = super().createEditor(parent, option, index)
    139 # make sure editor has same alignment as the display name
    140 editor.setAlignment(
--> 141     Qt.Alignment(index.data(Qt.ItemDataRole.TextAlignmentRole))
        editor = <PyQt6.QtWidgets.QLineEdit object at 0x2aaa3e4d0>
        index = <PyQt6.QtCore.QModelIndex object at 0x16b74ee30>
        Qt = <class 'PyQt6.QtCore.Qt'>
        Qt.ItemDataRole.TextAlignmentRole = <ItemDataRole.TextAlignmentRole: 7>
    142 )
    143 return editor

AttributeError: type object 'Qt' has no attribute 'Alignment'
```

## Expected behavior

Double-clicking the layer should allow editing the layer name and not raise an exception.

## Environment

napari: 0.5.0a2.dev129+g0dfb37b47.d20230518
Platform: macOS-13.3.1-arm64-arm-64bit
System: MacOS 13.3.1
Python: 3.10.9 (main, Feb 3 2023, 15:40:08) [Clang 14.0.0 (clang-1400.0.29.202)]
Qt: 6.5.0
PyQt6: 
NumPy: 1.24.1
SciPy: 1.10.0
Dask: 2023.1.1
VisPy: 0.12.3.dev45+dirty
magicgui: 0.6.1
superqt: unknown
in-n-out: 0.1.6
app-model: 0.1.1.dev3+gdf48c9d
npe2: 0.6.2

OpenGL:
- GL version: 2.1 Metal - 83.1
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 2560x1440, scale 1.0

Settings path:
- /Users/aandersoniii/Library/Application Support/napari/venv_640f7def1935afdf07a142187e645430c6d70fe6/settings.yaml


Discussion:

Resolving patch:
diff --git a/napari/_qt/containers/_layer_delegate.py b/napari/_qt/containers/_layer_delegate.py
--- a/napari/_qt/containers/_layer_delegate.py
+++ b/napari/_qt/containers/_layer_delegate.py
@@ -138,7 +138,7 @@ def createEditor(
         editor = super().createEditor(parent, option, index)
         # make sure editor has same alignment as the display name
         editor.setAlignment(
-            Qt.Alignment(index.data(Qt.ItemDataRole.TextAlignmentRole))
+            Qt.AlignmentFlag(index.data(Qt.ItemDataRole.TextAlignmentRole))
         )
         return editor
 


Test patch:
diff --git a/napari/_qt/containers/_tests/test_qt_layer_list.py b/napari/_qt/containers/_tests/test_qt_layer_list.py
--- a/napari/_qt/containers/_tests/test_qt_layer_list.py
+++ b/napari/_qt/containers/_tests/test_qt_layer_list.py
@@ -2,6 +2,7 @@
 
 import numpy as np
 from qtpy.QtCore import QModelIndex, Qt
+from qtpy.QtWidgets import QLineEdit, QStyleOptionViewItem
 
 from napari._qt.containers import QtLayerList
 from napari.components import LayerList
@@ -52,3 +53,13 @@ def check_state_at_layer_index(
     # The data method returns integer value of the enum in some cases, so
     # ensure it has the enum type for more explicit assertions.
     return Qt.CheckState(value)
+
+
+def test_createEditor(qtbot):
+    view, image = make_qt_layer_list_with_layer(qtbot)
+    model_index = layer_to_model_index(view, 0)
+    delegate = view.itemDelegate()
+    editor = delegate.createEditor(view, QStyleOptionViewItem(), model_index)
+    assert isinstance(editor, QLineEdit)
+    delegate.setEditorData(editor, model_index)
+    assert editor.text() == image.name