From 4c2e1970f260a9688f7bf528657f0e1351b73ee3 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Sun, 23 Feb 2020 21:18:46 +0100 Subject: [PATCH] qt receive tab: better "Clear" behaviour Previously, the selection would not get cleared, and if the user clicked again on the already selected item, the click would get ignored (request would not get populated). --- electrum/gui/qt/main_window.py | 1 + electrum/gui/qt/request_list.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index ac4b98c03..afa22a1ce 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1206,6 +1206,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger): self.receive_amount_e.setAmount(None) self.expires_label.hide() self.expires_combo.show() + self.request_list.clearSelection() def toggle_qr_window(self): from . import qrwindow diff --git a/electrum/gui/qt/request_list.py b/electrum/gui/qt/request_list.py index 40dc72b78..27c832f8d 100644 --- a/electrum/gui/qt/request_list.py +++ b/electrum/gui/qt/request_list.py @@ -27,7 +27,7 @@ from enum import IntEnum from PyQt5.QtGui import QStandardItemModel, QStandardItem from PyQt5.QtWidgets import QMenu -from PyQt5.QtCore import Qt, QItemSelectionModel +from PyQt5.QtCore import Qt, QItemSelectionModel, QModelIndex from electrum.i18n import _ from electrum.util import format_time, get_request_status @@ -75,7 +75,9 @@ class RequestList(MyTreeView): self.selectionModel().setCurrentIndex(item, QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows) break - def item_changed(self, idx): + def item_changed(self, idx: QModelIndex): + if not idx.isValid(): + return # TODO use siblingAtColumn when min Qt version is >=5.11 item = self.model().itemFromIndex(idx.sibling(idx.row(), self.Columns.DATE)) request_type = item.data(ROLE_REQUEST_TYPE) @@ -91,6 +93,10 @@ class RequestList(MyTreeView): self.parent.receive_payreq_e.setText(req.get('URI')) self.parent.receive_address_e.setText(req['address']) + def clearSelection(self): + super().clearSelection() + self.selectionModel().clearCurrentIndex() + def refresh_status(self): m = self.model() for r in range(m.rowCount()):