我想让鼠标进入和离开widget(spreenSplash类型的窗口)时,显示不同的光标,因此重写了leaveEvent和enterEvent,但是没有起作用。请教,问题可能出在哪里?
- C/C++ code
void SplashScreen::enterEvent( QEvent* event ){ if( event->type() == QEvent::Enter ) { QCursor cursor( Qt::WaitCursor ); this->setCursor( cursor ); }}void SplashScreen::leaveEvent( QEvent* event ){ if( event->type() == QEvent::Leave ) { QCursor cursor( Qt::ArrowCursor ); this->setCursor( cursor ); }}
------解决方案--------------------
不用加if( event->type() == QEvent::Enter )
直接
- C/C++ code
void SplashScreen::enterEvent( QEvent* event ){ QCursor cursor( Qt::WaitCursor ); this->setCursor( cursor );}
------解决方案--------------------
要设置mousetracking属性吧
This property holds whether mouse tracking is enabled for the widget.
If mouse tracking is disabled (the default), the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved.
If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed.
Access functions:
bool hasMouseTracking () const
void setMouseTracking ( bool enable )