問題描述
我正在使用 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 查看器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!