在drop事件后打开对话框时,Qt鼠标光标不会改变(Qt mouse cursor does not change when opening dialog after drop event)

我正在使用Qt for C ++并有一个dropEvent打开一个对话框。 但是,当对话框打开时,鼠标光标会保留拖放光标,而不是返回到通用默认光标。 这是奇怪的行为,尤其是在单击对话框上的按钮时。 下面是我的dropEvent代码的大致轮廓。

MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

注意:不幸的是我还不能发布游标的图片,因为我没有足够的代表。

I am using Qt for C++ and have a dropEvent which opens a dialog. However when the dialog opens, the mouse cursor retains the drop cursor instead of going back to the generic default cursor. This is strange behavior especially while clicking on buttons on the dialog. Below is a rough outline of my dropEvent code.

MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

NOTE: Unfortunately I cannot post pictures of the cursors yet because I do not have enough rep.

最满意答案

下面是我正在使用的解决方法,因为将对话框代码从exec更改为show是不可行的。

MyClass::MyClass() { //qRegisterMetaType was necessary for two of my parameters. qRegisterMetaType<arg1>("arg1"); qRegisterMetaType<arg2>("arg2"); connect(this, SIGNAL(signalDialog(arg1, arg2, arg3)), this, SLOT(runDialog(arg1, arg2, arg3)), Qt::QueuedConnection); } MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); emit signalDialog(arg1, arg2, arg3); } MyClass::runDialog(arg1, arg2, arg3) { MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

光标已正确更改回默认值。

Below is a workaround that I am using since it isn't feasible to change the dialog code from exec to show.

MyClass::MyClass() { //qRegisterMetaType was necessary for two of my parameters. qRegisterMetaType<arg1>("arg1"); qRegisterMetaType<arg2>("arg2"); connect(this, SIGNAL(signalDialog(arg1, arg2, arg3)), this, SLOT(runDialog(arg1, arg2, arg3)), Qt::QueuedConnection); } MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); emit signalDialog(arg1, arg2, arg3); } MyClass::runDialog(arg1, arg2, arg3) { MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

The cursor was changed back to the default correctly.

在drop事件后打开对话框时,Qt鼠标光标不会改变(Qt mouse cursor does not change when opening dialog after drop event)

我正在使用Qt for C ++并有一个dropEvent打开一个对话框。 但是,当对话框打开时,鼠标光标会保留拖放光标,而不是返回到通用默认光标。 这是奇怪的行为,尤其是在单击对话框上的按钮时。 下面是我的dropEvent代码的大致轮廓。

MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

注意:不幸的是我还不能发布游标的图片,因为我没有足够的代表。

I am using Qt for C++ and have a dropEvent which opens a dialog. However when the dialog opens, the mouse cursor retains the drop cursor instead of going back to the generic default cursor. This is strange behavior especially while clicking on buttons on the dialog. Below is a rough outline of my dropEvent code.

MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

NOTE: Unfortunately I cannot post pictures of the cursors yet because I do not have enough rep.

最满意答案

下面是我正在使用的解决方法,因为将对话框代码从exec更改为show是不可行的。

MyClass::MyClass() { //qRegisterMetaType was necessary for two of my parameters. qRegisterMetaType<arg1>("arg1"); qRegisterMetaType<arg2>("arg2"); connect(this, SIGNAL(signalDialog(arg1, arg2, arg3)), this, SLOT(runDialog(arg1, arg2, arg3)), Qt::QueuedConnection); } MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); emit signalDialog(arg1, arg2, arg3); } MyClass::runDialog(arg1, arg2, arg3) { MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

光标已正确更改回默认值。

Below is a workaround that I am using since it isn't feasible to change the dialog code from exec to show.

MyClass::MyClass() { //qRegisterMetaType was necessary for two of my parameters. qRegisterMetaType<arg1>("arg1"); qRegisterMetaType<arg2>("arg2"); connect(this, SIGNAL(signalDialog(arg1, arg2, arg3)), this, SLOT(runDialog(arg1, arg2, arg3)), Qt::QueuedConnection); } MyClass::dropEvent(QDropEvent *event) { //do some stuff event->accept(); emit signalDialog(arg1, arg2, arg3); } MyClass::runDialog(arg1, arg2, arg3) { MyDialog::runDialog(arg1, arg2, arg3); } MyDialog::runDialog(arg1, arg2, arg3) { MyDialog dlg(arg1, arg2, arg3); if(dlg.exec() == QDialog::Accepted) { //do some stuff } }

The cursor was changed back to the default correctly.