GUI: Fix shift-click selection on macOS

Implement custom mouse press event handling for macOS to properly support shift-click range selection in the transfer list. This addresses the issue reported in QTBUG-115838.
This commit is contained in:
Luke Memet 2025-02-14 20:47:44 -05:00
commit edb7755fa4
2 changed files with 42 additions and 1 deletions

View file

@ -1446,3 +1446,38 @@ void TransferListWidget::wheelEvent(QWheelEvent *event)
QTreeView::wheelEvent(event); // event delegated to base class QTreeView::wheelEvent(event); // event delegated to base class
} }
#ifdef Q_OS_MACOS
void TransferListWidget::mousePressEvent(QMouseEvent *event)
{
const QModelIndex clickedIndex = indexAt(event->pos());
if (!clickedIndex.isValid())
{
QTreeView::mousePressEvent(event);
return;
}
const Qt::KeyboardModifiers modifiers = event->modifiers();
const bool shiftPressed = modifiers.testFlag(Qt::ShiftModifier);
const bool cmdPressed = modifiers.testFlag(Qt::ControlModifier); // Command key on macOS
if (shiftPressed && m_lastClickedIndex.isValid())
{
// Handle shift-click range selection
const QItemSelection selection(m_lastClickedIndex, clickedIndex);
if (cmdPressed)
selectionModel()->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
else
selectionModel()->select(selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
selectionModel()->setCurrentIndex(clickedIndex, QItemSelectionModel::NoUpdate);
event->accept();
return;
}
// For non-shift clicks, update the last clicked index
if (!(modifiers & (Qt::AltModifier | Qt::MetaModifier))) // Ignore if Alt/Meta is pressed
m_lastClickedIndex = clickedIndex;
QTreeView::mousePressEvent(event);
}
#endif

View file

@ -118,11 +118,14 @@ private slots:
void askNewCategoryForSelection(); void askNewCategoryForSelection();
void saveSettings(); void saveSettings();
private: protected:
void dragEnterEvent(QDragEnterEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override;
void dropEvent(QDropEvent *event) override; void dropEvent(QDropEvent *event) override;
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
private:
QModelIndex mapToSource(const QModelIndex &index) const; QModelIndex mapToSource(const QModelIndex &index) const;
QModelIndexList mapToSource(const QModelIndexList &indexes) const; QModelIndexList mapToSource(const QModelIndexList &indexes) const;
QModelIndex mapFromSource(const QModelIndex &index) const; QModelIndex mapFromSource(const QModelIndex &index) const;
@ -139,4 +142,7 @@ private:
TransferListModel *m_listModel = nullptr; TransferListModel *m_listModel = nullptr;
TransferListSortModel *m_sortFilterModel = nullptr; TransferListSortModel *m_sortFilterModel = nullptr;
#ifdef Q_OS_MACOS
QPersistentModelIndex m_lastClickedIndex; // For handling shift-click selection on macOS
#endif
}; };