Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.5.2, 4.7.1
-
None
-
Windows
Description
Attached is some sample code, which, when compiled, brings up a simple line edit widget. The mouse cursor changes every five seconds just fine between Qt::SizeVerCursor and Qt::SizeHorCursor via a timer callback.
Pressing the right button in the widget changes the cursor temporarily to Qt::WaitCursor.
However, if you right click to bring up the context menu, then move the mouse away from the menu but still over the widget, then stop moving the mouse, the cursor does not update, even though calls are still being made to setCursor via the timer.
Example code::
#include <QtGui> namespace local { class LineEdit : public QLineEdit { public: LineEdit(); virtual void mousePressEvent(QMouseEvent *MouseEvent); virtual void mouseReleaseEvent(QMouseEvent *MouseEvent); virtual void timerEvent(QTimerEvent *TimerEvent); private: int m_timerId; Qt::CursorShape myCursorShape; }; } local::LineEdit::LineEdit() : QLineEdit(), myCursorShape(Qt::IBeamCursor) { // Change the cursor every two seconds. // You need to keep the timer id here so that you change the cursor correctly. m_timerId = startTimer(2000); } void local::LineEdit::mousePressEvent(QMouseEvent *MouseEvent) { qDebug("In local::LineEdit::mousePressEvent"); if (MouseEvent->button() == Qt::RightButton) { setCursor(Qt::WaitCursor); } } void local::LineEdit::mouseReleaseEvent(QMouseEvent *MouseEvent) { qDebug("In local::LineEdit::mouseReleaseEvent"); if (MouseEvent->button() == Qt::RightButton) { setCursor(Qt::IBeamCursor); } } void local::LineEdit::timerEvent(QTimerEvent *timerEvent) { qDebug() << "TimerEvent" << timerEvent->timerId(); if ( m_timerId == timerEvent->timerId()) { myCursorShape = (myCursorShape == Qt::IBeamCursor) ? Qt::SizeHorCursor : (myCursorShape == Qt::SizeHorCursor ? Qt::SizeVerCursor : Qt::SizeHorCursor); qDebug() << "I am now changing the cursor"; setCursor(myCursorShape); } } int main(int Argc, char *Argv[]) { QApplication a(Argc, Argv); QMainWindow *mainWindow = new QMainWindow(); mainWindow->setCentralWidget(new local::LineEdit()); mainWindow->show(); return a.exec(); }