QT QPushButton Press Event



我想在按下QT按钮但失败时进行非常耗时的操作,有人可以帮我解释一下吗? 谢谢! 代码为:

bool eventFilter(QObject *target, QEvent *event)
{
if (target == ui.zoominBtn){
if (event->type() == QEvent::MouseButtonPress){
phcs[curPhcId].zoom(0.1);
renderRaytracingImage();
}
}
return QMainWindow::eventFilter(target, event);
}

现在我将耗时的部分移动到 QThread:

if (target == ui.zoominBtn){
if (event->type() == QEvent::MouseButtonPress){
//phcs[curPhcId].zoom(0.1);
TracerayThread *traceThread = new TracerayThread(&scene,&(phcs[curPhcId]),this);
connect(traceThread, SIGNAL(resultReady()), this, SLOT(render()));
connect(traceThread, SIGNAL(finished()), traceThread, SLOT(deleteLater()));
traceThread->start();
}
}

我需要传递两个指向新线程的指针,我可以这样做吗?

您可以使用 QPushButton 点击信号。

connect(YourButtonName,  &QPushButton::clicked, this, &MainWindow::YourSlotName);

如果你想使用它,不要忘记installEventFilter

最新更新