QT 5.5 将外部应用程序嵌入到 QWidget 中 [英] QT 5.5 embed external application into QWidget

查看:53
本文介绍了QT 5.5 将外部应用程序嵌入到 QWidget 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣在我的基于 QT 5.5 Widget 的应用程序中嵌入一个外部应用程序.我只关心它在 Linux 上的工作.我正在使用 CentOS 7 和 GNOME.

I'm interested in embedding an external application inside of my QT 5.5 Widget based application. I'm only concerned with it working on Linux. I'm using CentOS 7 with GNOME.

这是我试过的代码:

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);

    QWindow *window = QWindow::fromWinId(125829124);
    QWidget *widget = QWidget::createWindowContainer(window);
    widget->setParent(this);
    QVBoxLayout *layout = new QVBoxLayout();
    layout->addWidget(widget);
    this->setLayout(layout);
}

在此示例中,我单独获取 WinId 并仅对值进行硬编码以进行测试.要嵌入的应用程序正在运行.

In this example I'm getting the WinId separately and just hard-coding the value for testing. The application to be embedded is running.

当我执行我的应用程序时,它运行没有错误.并且要嵌入的应用程序会更改屏幕位置并调整大小,但它不会嵌入到我的应用程序中.它仍然是一个单独的窗口.如果我杀死我的应用程序,嵌入的应用程序也会被杀死.

When I execute my Application it runs with no errors. And the application to be embedded changes screen position and resizes, however it does not embed inside my application. It is still a separate window. If I kill my application, the embedded application is killed as well.

那么有没有办法将应用程序实际嵌入到我的应用程序中?

So is there a way to actually embed the application inside of my application?

*************** 更新 ****************

*************** UPDATE ****************

我刚刚发现了一些有趣的东西.当我运行我的应用程序(容器应用程序)时,第二个应用程序(我想要嵌入的那个)在我的应用程序之外仍然是一个独立的窗口.但是,如果我调整应用程序窗口的大小(单击右下角调整窗口大小),第二个应用程序(要嵌入的)也会调整大小,但在我的容器应用程序之外仍然是一个独立的窗口.

Something interesting I just uncovered. When I run my application (container application) the second application (the one I want embedded) remains an independent Window outside of my application. However if I resize my application window (click the lower right corner to resize the window) the second application (to be embedded) resizes as well, but remains an independent Window outside of my container application.

更有趣的是,如果我杀死我的应用程序,两个应用程序都会从​​桌面消失".但是系统监视器显示第二个应用程序(我想要嵌入的那个)仍在运行(但是没有 GUI).现在,如果我再次启动我的应用程序,第二个应用程序实际上已嵌入到我的容器应用程序中,这正是我想要的!

Even more interesting is that if I kill my application, both applications "disappear" from the desktop. However System Monitor shows the second application (the one I want embedded) is still running (however with no GUI). Now if I launch my application again the second application is in fact embedded in my container application, just the way I would like!

所以我想我必须弄清楚为什么杀死我的应用程序然后重新启动它会正确嵌入第二个应用程序.

So I guess I have to figure out why killing my application and then relaunching it embeds the second application correctly.

推荐答案

以下达到了预期的效果,关键是添加了FramelessWindowHint:

The following achieves the desired result, the key was adding the FramelessWindowHint:

QWindow *window = QWindow::fromWinId(211812356);
window->setFlags(Qt::FramelessWindowHint);

QWidget *widget = QWidget::createWindowContainer(window);

QVBoxLayout *layout = new QVBoxLayout(this);
layout->addWidget(widget);
this->setLayout(layout);

这篇关于QT 5.5 将外部应用程序嵌入到 QWidget 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆