当前位置: 代码迷 >> QT开发 >> qt event没有执行,该如何处理
  详细解决方案

qt event没有执行,该如何处理

热度:121   发布时间:2016-04-25 05:05:54.0
qt event没有执行
我想让鼠标进入和离开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 )
  相关解决方案