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

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

问题描述

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

这是我尝试过的代码:

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,并仅对值进行硬编码以进行测试.要嵌入的应用程序正在运行.

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

那么有没有一种方法可以将应用程序实际嵌入到我的应用程序中?

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

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

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

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

解决方案

以下实现了预期的结果,关键是添加了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);

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.

This is the code I have tried:

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);
}

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.

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.

解决方案

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天全站免登陆