1

在几秒钟不活动后,我试图在我的应用程序中自动隐藏鼠标,并使用下面的代码来处理这个问题。在我打开一个子窗口之前,一切都很好:直到我将鼠标移到子窗口上,鼠标才会重新出现。如果我监视 MyMainWindow::eventFilter() 中的所有事件,当子窗口打开时,我看不到父窗口的任何事件。我以为为应用程序的所有窗口qApp->installEventFilter()添加了事件过滤器。想法?

我的平台是 Windows 7 和 Qt 4.8。该应用程序在自助服务终端计算机上全屏运行——也就是说,除了我的应用程序之外,计算机上没有其他任何东西在运行。

MyMainWindow::MyMainWindow( QWidget *parent ) :
    QMainWindow( parent ),
    ui( new Ui::MyMainWindow )
{
    // all the other setup...
    hideMouseTimer.start( HideMouseDelay_ms );
    connect( &hideMouseTimer, SIGNAL(timeout()), this, SLOT(hideMouseTimerExpiry()) );

    if( qApp )
    {
        qApp->installEventFilter( this );
    }
}

bool MyMainWindow::eventFilter( QObject *obj, QEvent *event )
{
   /*
    * Monitor mouse movement. If the mouse has been hidden, show it and start
    * the timer for the next check for hiding it.
    */
   if( event->type() == QEvent::MouseMove )
   {
       qApp->restoreOverrideCursor();
       hideMouseTimer.start( HideMouseDelay_ms );
   }

   return QWidget::eventFilter( obj, event ); 
}

void MyMainWindow::hideMouseTimerExpiry()
{
    qApp->setOverrideCursor( QCursor( Qt::BlankCursor ) );
    hideMouseTimer.stop();
}

void MyMainWindow::on_dialog_clicked()
{
    myDiaglog *d = new myDialog();
    d->exec();
    delete d;
}
4

0 回答 0