From 23c6f7f70252711823a13c84e6461c5d56304a13 Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 26 Sep 2021 23:47:37 +0800 Subject: [PATCH] fix: cursor is always IBeam --- RedPandaIDE/editor.cpp | 23 +++++++++++++---------- RedPandaIDE/editor.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 20807ea2..2e3041a7 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -137,6 +137,8 @@ Editor::Editor(QWidget *parent, const QString& filename, setContextMenuPolicy(Qt::CustomContextMenu); connect(this, &QWidget::customContextMenuRequested, pMainWindow, &MainWindow::onEditorContextMenu); + + mOldHintCursor = Qt::IBeamCursor; } Editor::~Editor() { @@ -771,17 +773,13 @@ bool Editor::event(QEvent *event) return true; } - //qDebug()<'') then s = s.trimmed(); if ((s == mCurrentWord) && (mCurrentTipType == reason)) { -// QApplication* app = dynamic_cast(QApplication::instance()); -// if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) { if (helpEvent->modifiers() == Qt::ControlModifier) { + mOldHintCursor = cursor(); setCursor(Qt::PointingHandCursor); - } else { - setCursor(Qt::ArrowCursor); + } else if (cursor() == Qt::PointingHandCursor) { + setCursor(mOldHintCursor); } event->ignore(); return true; // do NOT remove hint when subject stays the same @@ -828,13 +826,17 @@ bool Editor::event(QEvent *event) // QApplication* app = dynamic_cast(QApplication::instance()); // if (app->keyboardModifiers().testFlag(Qt::ControlModifier)) { if (helpEvent->modifiers() == Qt::ControlModifier) { + mOldHintCursor = cursor(); setCursor(Qt::PointingHandCursor); - } else { - setCursor(Qt::ArrowCursor); + } else if (cursor() == Qt::PointingHandCursor) { + setCursor(mOldHintCursor); } QToolTip::showText(mapToGlobal(helpEvent->pos()),hint); event->ignore(); } else { + if (cursor() == Qt::PointingHandCursor) { + setCursor(mOldHintCursor); + } event->ignore(); } return true; @@ -2143,7 +2145,8 @@ void Editor::cancelHint() QToolTip::hideText(); mCurrentWord = ""; mCurrentTipType = TipType::None; - setCursor(Qt::IBeamCursor); + if (cursor() == Qt::PointingHandCursor) + setCursor(mOldHintCursor); } QString Editor::getFileHint(const QString &s) diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index b62bc445..bd6ae439 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -229,6 +229,7 @@ private: TipType mCurrentTipType; QString mOldSelectionWord; QString mSelectionWord; + QCursor mOldHintCursor; bool mSaving;