2013-11-28 33 views
1

在我的应用程序中,我在打开文件(在菜单栏中使用QAction)后立即执行了广泛的算法。我想改变光标占线模式,但不知何故,我的代码无法正常工作:如何更改由QAction触发的插槽内的光标

MyApp::MyApp(QWidget *parent) 
    : QMainWindow(parent) 
{ 
    ui.setupUi(this); 
    connect(ui.openFileOption, SIGNAL(triggered()), this, SLOT(OpenFileAction())); 
} 

MyApp::~MyApp() 
{ 
} 

void MyApp::OpenFileAction() 
{ 
    //change cursor 
    this->setCursor(Qt::WaitCursor); 
    QApplication::processEvents(); 

    // load file 

    // do something long here... 

    this->setCursor(Qt::ArrowCursor); 
} 
+0

你试过设置processEvents()后面的游标; – drescherjm

+0

不起作用:) – azer89

回答

0

你可以试试下面的代码(由Qt文档提供,顺便说一句):

QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); 
// load file 
// do something long here... 
QApplication::restoreOverrideCursor(); 
+0

是的,它的工作原理,但它不能在由QAction触发的SLOT函数中工作(在我的GUI中,我在菜单栏上有按钮...) – azer89