更新一下程序(嵌套窗口鼠標(biāo)滾輪事件無效解決)
h頭文件
//加載Unity3D窗口
void loadWindowUnity3DExe(std::function f);
cpp文件
/**
* 加載Unity3D窗口
* @brief loadWindowUnity3DExe
* @return
*/
void loadWindowUnity3DExe(std::function f)
{
? ? QString cmd = QDir::currentPath()+"/model0714/motioncapture.exe";
? ? QFileInfo file(cmd);
? ? if(file.exists()==false){
? ? ? ? f(0);
? ? ? ? return;
? ? }
? ? //啟動exe程序
? ? QProcess myprocess;
? ? myprocess.startDetached(cmd,QStringList());
? ? WId wid = 0;
? ? do
? ? {
? ? ? ? QEventLoop loop;
? ? ? ? QTimer::singleShot(1, &loop, SLOT(quit()));
? ? ? ? loop.exec();
? ? ? ? wid = (WId)FindWindow(L"UnityWndClass",L"motioncapture");
? ? }while(wid == 0);
? ? f(wid);
}
mainwindow.cpp文件
//加載Unity3D
? ? loadWindowUnity3DExe([=](WId wid){
? ? ? ? //代表文件不存在或者沒找到wid
? ? ? ? if(wid == 0){
? ? ? ? ? ? QMessageBox::warning(this,"提示",messagelist[4]);
? ? ? ? }else {
? ? ? ? ? ? QWindow *m_window= QWindow::fromWinId(wid);
? ? ? ? ? ? m_window->setFlags(m_window->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
? ? ? ? ? ? QWidget *unityWidget = QWidget::createWindowContainer(m_window,ui->centralwidget);
? ? ? ? ? ? //unityWidget->setAttribute(Qt::WA_QuitOnClose);
? ? ? ? ? ? setCentralWidget(unityWidget);
? ? ? ? }
? ? });
以下是最新的內(nèi)容,嵌套的窗體支持鼠標(biāo)事件,具體如下:
首先是新建mainwindow, 自定義主窗口widget嵌套窗體后莺奔,不確定鼠標(biāo)事件有效。
通過QProcess開啟嵌套窗口并添加
QProcess *myprocess = new QProcess;
? ? QString cmd = QDir::currentPath()+"/model0714/motioncapture.exe";
? ? QFileInfo file(cmd);
? ? if(file.exists()){
? ? ? ? QStringList arguments;
? ? ? ? arguments<<"-style"<<"fusion";
? ? ? ? myprocess->setWorkingDirectory(QDir::currentPath()+"/model0714");
? ? ? ? myprocess->setProcessChannelMode(QProcess::MergedChannels);
? ? ? ? myprocess->start(cmd, arguments);
? ? ? ? WId wid = 0;
? ? ? ? do
? ? ? ? {
? ? ? ? ? ? QEventLoop loop;
? ? ? ? ? ? QTimer::singleShot(1, &loop, SLOT(quit()));
? ? ? ? ? ? loop.exec();
? ? ? ? ? ? wid = (WId)FindWindow(L"UnityWndClass",L"motioncapture");
? ? ? ? }while(wid == 0);
? ? ? ? QWindow *m_window= QWindow::fromWinId(wid);
? ? ? ? m_window->setFlags(m_window->flags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::FramelessWindowHint);
? ? ? ? m_window->requestActivate();
? ? ? ? QWidget *unityWidget = QWidget::createWindowContainer(m_window,leftSplitter);
? ? ? ? unityWidget->setFocusPolicy(Qt::StrongFocus);
//鼠標(biāo)事件有效代碼
? ? ? ? AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL), GetCurrentThreadId(),TRUE);
? ? ? ? SetForegroundWindow(HWND(wid));
? ? ? ? SetFocus(HWND(wid));
? ? ? ? AttachThreadInput(GetWindowThreadProcessId(::GetForegroundWindow(),NULL), GetCurrentThreadId(),FALSE);
? ? }