Change click event handling for QTableWidget. Needs testing on MacOS and Windows

This commit is contained in:
Mizaki 2024-04-27 01:59:59 +01:00
parent 9359cd877d
commit 199167c50b
2 changed files with 8 additions and 21 deletions

View File

@ -1403,7 +1403,7 @@ class TaggerWindow(QtWidgets.QMainWindow):
for i, style in enumerate(self.load_data_styles):
item_idx = self.cbLoadDataStyle.findData(style)
self.cbLoadDataStyle.setItemChecked(item_idx, True)
# Order matters so move it
# Order matters, move items to list order
self.cbLoadDataStyle.moveItem(item_idx, row=i)
for style in unchecked:
self.cbLoadDataStyle.setItemChecked(self.cbLoadDataStyle.findData(style), False)

View File

@ -188,9 +188,7 @@ class HoverQLabel(QtWidgets.QLabel):
def mouseReleaseEvent(self, event: Any) -> None:
index: QModelIndex = self.combobox.tableWidget.indexAt(self.pos())
if self.combobox.justShown:
self.combobox.justShown = False
else:
if self.combobox.isShown:
self.combobox.toggleItem(index)
def resizeEvent(self, event: Any | None = None) -> None:
@ -244,7 +242,7 @@ class TableComboBox(QtWidgets.QComboBox):
self.tableWidget.viewport().installEventFilter(self)
# Keeps track of when the combobox list is shown
self.justShown = False
self.isShown = False
self.tableWidget.currentCellChanged.connect(self.current_cell_changed)
@ -303,24 +301,13 @@ class TableComboBox(QtWidgets.QComboBox):
def eventFilter(self, obj: Any, event: Any) -> bool:
# Allow events before the combobox list is shown
if obj == self.tableWidget.viewport():
# We record that the combobox list has been shown
if event.type() == QEvent.Show:
self.justShown = True
# We record that the combobox list has hidden,
# this will happen if the user does not make a selection
# but clicks outside of the combobox list or presses escape
if event.type() == QEvent.Hide:
self._updateText()
self.justShown = False
# QEvent.MouseButtonPress is inconsistent on activation because double clicks are a thing
if event.type() == QEvent.MouseButtonRelease:
# If self.justShown is true it means that they clicked on the combobox to change the checked items
# This is standard behavior (on macos) but I think it is surprising when it has a multiple select
# TODO The first click in the table is currently consumed
if self.justShown:
self.justShown = False
return True
self.isShown = False
if event.type() == QEvent.Show:
self.isShown = True
# QEvent.MouseButtonRelease will 'click' the selected row even if clicking outside to hide dropdown
if self.isShown and event.type() == QEvent.MouseButtonRelease:
# Find the current index and item
index = self.tableWidget.indexAt(event.pos())
self.toggleItem(index)