如何在 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_())
相关文章