Merge #19210: qt: Get rid of cursor in out-of-focus labels

bd315eb5e27d49d47759ae9417328427426cb269 qt: Get rid of cursor in out-of-focus labels (Hennadii Stepanov)

Pull request description:

  After clicking on `QLabel` with selectable text the cursor remains forever:

  ![47532924-65e7b200-d8ba-11e8-9254-7bde658961cb](https://user-images.githubusercontent.com/32963518/84038485-ad945200-a9a8-11ea-89e3-c7c17d02a611.png)

  This PR fixes this visual bug.

  Earlier attempts to fix this issue:
  - #14577
  - #14810 (combined with other UX feature)

ACKs for top commit:
  promag:
    Code review ACK bd315eb5e27d49d47759ae9417328427426cb269.
  laanwj:
    Tested ACK bd315eb5e27d49d47759ae9417328427426cb269

Tree-SHA512: 6bf89362412e5ce9a4dec6944b62fe44fc31ca49cda7f6e2eb37e847fac9dccb68bca7ac6877b19e42add2333e40d0b4265757ead105ac0a5d28f8ab43b322c3
This commit is contained in:
Wladimir J. van der Laan 2020-07-15 16:36:32 +02:00 committed by pasta
parent c5f3b478bf
commit 3b0144beeb
3 changed files with 39 additions and 0 deletions

View File

@ -577,6 +577,8 @@ int GuiMain(int argc, char* argv[])
/// 9. Main GUI initialization /// 9. Main GUI initialization
// Install global event filter that makes sure that long tooltips can be word-wrapped // Install global event filter that makes sure that long tooltips can be word-wrapped
app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app)); app.installEventFilter(new GUIUtil::ToolTipToRichTextFilter(TOOLTIP_WRAP_THRESHOLD, &app));
// Install global event filter that makes sure that out-of-focus labels do not contain text cursor.
app.installEventFilter(new GUIUtil::LabelOutOfFocusEventFilter(&app));
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
// Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION) // Install global event filter for processing Windows session related Windows messages (WM_QUERYENDSESSION and WM_ENDSESSION)
qApp->installNativeEventFilter(new WinShutdownMonitor()); qApp->installNativeEventFilter(new WinShutdownMonitor());

View File

@ -647,6 +647,28 @@ bool ToolTipToRichTextFilter::eventFilter(QObject *obj, QEvent *evt)
return QObject::eventFilter(obj, evt); return QObject::eventFilter(obj, evt);
} }
LabelOutOfFocusEventFilter::LabelOutOfFocusEventFilter(QObject* parent)
: QObject(parent)
{
}
bool LabelOutOfFocusEventFilter::eventFilter(QObject* watched, QEvent* event)
{
if (event->type() == QEvent::FocusOut) {
auto focus_out = static_cast<QFocusEvent*>(event);
if (focus_out->reason() != Qt::PopupFocusReason) {
auto label = qobject_cast<QLabel*>(watched);
if (label) {
auto flags = label->textInteractionFlags();
label->setTextInteractionFlags(Qt::NoTextInteraction);
label->setTextInteractionFlags(flags);
}
}
}
return QObject::eventFilter(watched, event);
}
void TableViewLastColumnResizingFixer::connectViewHeadersSignals() void TableViewLastColumnResizingFixer::connectViewHeadersSignals()
{ {
connect(tableView->horizontalHeader(), &QHeaderView::sectionResized, this, &TableViewLastColumnResizingFixer::on_sectionResized); connect(tableView->horizontalHeader(), &QHeaderView::sectionResized, this, &TableViewLastColumnResizingFixer::on_sectionResized);

View File

@ -212,6 +212,21 @@ namespace GUIUtil
int size_threshold; int size_threshold;
}; };
/**
* Qt event filter that intercepts QEvent::FocusOut events for QLabel objects, and
* resets their `textInteractionFlags' property to get rid of the visible cursor.
*
* This is a temporary fix of QTBUG-59514.
*/
class LabelOutOfFocusEventFilter : public QObject
{
Q_OBJECT
public:
explicit LabelOutOfFocusEventFilter(QObject* parent);
bool eventFilter(QObject* watched, QEvent* event) override;
};
/** /**
* Makes a QTableView last column feel as if it was being resized from its left border. * Makes a QTableView last column feel as if it was being resized from its left border.
* Also makes sure the column widths are never larger than the table's viewport. * Also makes sure the column widths are never larger than the table's viewport.