diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 95814c0e6..6fb71bfaa 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -312,10 +312,7 @@ void TransferListWidget::torrentDoubleClicked() case PREVIEW_FILE: if (torrentContainsPreviewableFiles(torrent)) { - auto *dialog = new PreviewSelectDialog(this, torrent); - dialog->setAttribute(Qt::WA_DeleteOnClose); - connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile); - dialog->show(); + openPreviewSelectDialog(torrent); } else { @@ -617,10 +614,7 @@ void TransferListWidget::previewSelectedTorrents() { if (torrentContainsPreviewableFiles(torrent)) { - auto *dialog = new PreviewSelectDialog(this, torrent); - dialog->setAttribute(Qt::WA_DeleteOnClose); - connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile); - dialog->show(); + openPreviewSelectDialog(torrent); } else { @@ -1449,3 +1443,13 @@ void TransferListWidget::wheelEvent(QWheelEvent *event) QTreeView::wheelEvent(event); // event delegated to base class } + +void TransferListWidget::openPreviewSelectDialog(const BitTorrent::Torrent *torrent) +{ + auto *dialog = new PreviewSelectDialog(this, torrent); + dialog->setAttribute(Qt::WA_DeleteOnClose); + // Qt::QueuedConnection is required to prevent a bug on wayland compositors where the preview won't open. + // It occurs when the window focus shifts immediately after TransferListWidget::previewFile has been called. + connect(dialog, &PreviewSelectDialog::readyToPreviewFile, this, &TransferListWidget::previewFile, Qt::QueuedConnection); + dialog->show(); +} diff --git a/src/gui/transferlistwidget.h b/src/gui/transferlistwidget.h index c5b24ba24..097dd809a 100644 --- a/src/gui/transferlistwidget.h +++ b/src/gui/transferlistwidget.h @@ -123,6 +123,7 @@ private: void dragMoveEvent(QDragMoveEvent *event) override; void dropEvent(QDropEvent *event) override; void wheelEvent(QWheelEvent *event) override; + void openPreviewSelectDialog(const BitTorrent::Torrent *torrent); QModelIndex mapToSource(const QModelIndex &index) const; QModelIndexList mapToSource(const QModelIndexList &indexes) const; QModelIndex mapFromSource(const QModelIndex &index) const;