How to embed a pptk viewer in a PyQt5 window

后端 未结 3 812
灰色年华
灰色年华 2020-12-22 12:03

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 (

3条回答
  •  轮回少年
    2020-12-22 12:22

    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.

    enter image description here

    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_())
    

提交回复
热议问题