如何在PyQt5窗口中嵌入pptk查看器 [英] How to embed a pptk viewer in a PyQt5 window

查看:488
本文介绍了如何在PyQt5窗口中嵌入pptk查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PyQt5(Qt Designer)构建GUI程序,该程序也使用 pptk库。这个库可以绘制大量的点,这对我而言非常有趣(显示有限元素后处理结果)。

I am building a GUI program with PyQt5 (Qt Designer) which also uses the pptk library. This library can plot huge amount of points which is very interesting for my purpose (display finite element post processing results).

这篇文章,来自pptk的查看器类是一个独立的窗口。像上一篇文章的作者一样,我想将查看器嵌入到我的GUI中。看来我需要写一些包装器。经过研究,我仍然不知道这是否意味着我必须查看C ++代码才能重新编写一些内容。在这种情况下,它会比我想象的要复杂,我暂时必须放弃。最后,如果我可以创建一个可以集成到主窗口中的查看器小部件,那就太完美了。

As it is explained in this post, the viewer class from pptk is a standalone window. Like the author of the previous post, I would like to embed the viewer in my GUI. It seems that I need to write some wrapper. After some research, I still don't know if that means that I have to look inside the C++ code to re-write some stuff. In that case, it'll be more complex than I thought and I'll have to give up for the moment. In the end, if I could create a viewer widget that can be integrated inside my main window, it would be perfect.

有人可以帮我澄清一下我必须做什么吗?

Can someone please clarify for me what I have to go through?

推荐答案

下面是一个演示脚本,显示了如何将查看器添加到布局。我无法在Windows上对其进行测试,但是在Linux上(没有 win32gui 部分),我得到的结果如下所示。如您所见,没有奇怪的边框,并且可以正常调整窗口的大小。

Below is a demo script that shows how to add the viewer to a layout. I cannot test it on Windows, but on Linux (without the win32gui part), I get the results show below. As you can see, there is no weird border, and the window can be freely resized as normal.

from PyQt5 import QtWidgets, QtGui
import numpy as np
import pptk
import win32gui
import sys

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        widget = QtWidgets.QWidget()
        layout = QtWidgets.QGridLayout(widget)
        self.setCentralWidget(widget)

        self.cloudpoint = np.random.rand(100, 3)
        self.v = pptk.viewer(self.cloudpoint)
        hwnd = win32gui.FindWindowEx(0, 0, None, "viewer")
        self.window = QtGui.QWindow.fromWinId(hwnd)    
        self.windowcontainer = self.createWindowContainer(self.window, widget)

        layout.addWidget(self.windowcontainer, 0, 0)

if __name__ == '__main__':

    app = QtWidgets.QApplication(sys.argv)
    app.setStyle("fusion")
    form = MainWindow()
    form.setWindowTitle('PPTK Embed')
    form.setGeometry(100, 100, 600, 500)
    form.show()
    sys.exit(app.exec_())

这篇关于如何在PyQt5窗口中嵌入pptk查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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