diff --git a/glue/core/qt/layer_artist_model.py b/glue/core/qt/layer_artist_model.py index c58c0d9a0..6c9994fb7 100644 --- a/glue/core/qt/layer_artist_model.py +++ b/glue/core/qt/layer_artist_model.py @@ -82,10 +82,15 @@ def setData(self, index, value, role): if role == Qt.EditRole: self.change_label(index.row(), str(value)) if role == Qt.CheckStateRole: - vis = value == Qt.Checked + if isinstance(value, int): + try: # Qt6 + vis = value == Qt.Checked.value # https://bugreports.qt.io/browse/QTBUG-104688 + except AttributeError: # Qt5 + vis = value == Qt.Checked + else: + vis = value == Qt.Checked self.artists[index.row()].visible = vis self.artists[index.row()].redraw() - self.dataChanged.emit(index, index) return True diff --git a/glue/core/qt/tests/test_layer_artist_model.py b/glue/core/qt/tests/test_layer_artist_model.py index 8863eb1c2..1bee8a90e 100644 --- a/glue/core/qt/tests/test_layer_artist_model.py +++ b/glue/core/qt/tests/test_layer_artist_model.py @@ -194,15 +194,36 @@ def test_check_syncs_to_visible(): m0.visible = True assert m0.visible - assert model.data(model.index(0), Qt.CheckStateRole) == Qt.Checked + assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Checked m0.visible = False assert not m0.visible - assert model.data(model.index(0), Qt.CheckStateRole) == Qt.Unchecked + assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Unchecked - model.setData(model.index(0), Qt.Checked, Qt.CheckStateRole) + model.setData(model.index(0), Qt.CheckState.Checked, Qt.CheckStateRole) assert m0.visible +def test_artist_check_uncheck_works(): + """ + Because of https://bugreports.qt.io/browse/QTBUG-104688, under Qt6 + the checkbox in the UI actually sends a bare integer (0 for unchecked, + 2 for checked) so we have to check this against Qt.CheckState.Checked.value + in setData. This is a regression test for this behavior. + """ + mgrs = [LayerArtist(Data(label='A'))] + mgrs[0].artists = [MagicMock()] + + model = LayerArtistModel(mgrs) + mgrs[0].visible = True + assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Checked + + model.setData(model.index(0), 0, Qt.CheckStateRole) + assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Unchecked + + model.setData(model.index(0), 2, Qt.CheckStateRole) + assert model.data(model.index(0), Qt.CheckStateRole) == Qt.CheckState.Checked + + def test_data(): model, mgrs = setup_model(3)