将GLViewWidget插入到特定p处的GraphicsWindow中

2024-09-30 22:20:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前已经建立了一个图形用户界面,它同时显示一个列表和一个图像,我也想同时显示当前周围的点云,并能够访问图形用户界面中的所有内容。你知道吗

我试过VTK可视化工具,问题是渲染循环会阻塞其他所有内容,直到窗口关闭。你知道吗

我目前正在尝试使用PyQtGraph的GLViewWidget,但是我不能像我想的那样将它插入到位置上,并且能够处理GUI中的其他项目。你知道吗

我必须将窗口指定为父窗口,这样才能看到小部件。但是它跳进了窗户的左角。你知道吗

    def init_gui(self, win_height=800, win_width=1800):
        #self.w = self
        #self.w.scene().sigMouseClicked.connect(self.mousePressEvent) #mouseMoveEvent
        #self.w.scene().sigMouseMoved.connect(self.mouseMoveEvent)
        pg.setConfigOptions(imageAxisOrder='row-major')
        pg.setConfigOption('background', 'w')
        pg.setConfigOption('foreground', 'k')
        self.w = pg.GraphicsWindow(size=(win_width,win_height), border=True)
        self.list_imgs       = QtGui.QListWidget()
        self.list_marks      = QtGui.QListWidget()
        self.btn_Del_Mark    = QtGui.QPushButton('Del Mark')
        self.btn_MarkPed     = QtGui.QPushButton('Mark ped')
        self.btn_MarkCycl    = QtGui.QPushButton('Mark cyc')
        self.btn_MarkCar     = QtGui.QPushButton('Mark car')
        self.btn_Rst         = QtGui.QPushButton('Reset JSON')
        self.btn_Save        = QtGui.QPushButton('Save JSON')
        self.btn_Next        = QtGui.QPushButton('Next ->')
        self.btn_Back        = QtGui.QPushButton('Back <-')
        self.btn_Predict_2D  = QtGui.QPushButton('Predict 2D')
        self.btn_Predict_3D  = QtGui.QPushButton('Predict 3D')
        self.btn_Pipeline    = QtGui.QPushButton('Run Pipeline')
        self.lbl_list1       = QtGui.QLabel()
        self.lbl_list2       = QtGui.QLabel()

        self.lbl_img_path    = QtGui.QLabel()
        self.lbl_list1.setText("Images")
        self.lbl_list2.setText("Markings")
        self.w.setWindowTitle('Visualizing traffic situation')
        self.vb = pg.ViewBox()
        self.vb.setAspectLocked()
        self.img = pg.ImageItem()
        self.vb.addItem(self.img)
        self.vb.invertY(True)
        layout = pg.GraphicsLayout()
        self.lbl_list1.setAlignment(QtCore.Qt.AlignCenter)
        self.lbl_list2.setAlignment(QtCore.Qt.AlignCenter)
        #self.qgwidg = QtGui.Qg
        self.graph_3d        = gl.GLViewWidget(parent=self.w)
        self.graph_3d.opts['distance'] = 20
        self.graph_3d.show()
        self.graph_3d.setParent(self.w)
        #self.graph_3d.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
        self.graph_3d.setMinimumSize(800, 400)

        offset_grp_1 = 2
        offset_grp_2 = 3
        offset_grp_3 = 4

        layout.addItem(self.vb                             , 1,  9, 6,  20)
        layout.addItem(self.proxyWidget(self.graph_3d, width=(600), height=(500)), 10, 3, 10, 20)
        layout.addItem(self.proxyWidget(self.lbl_list1     , width=(int(1./10.*win_width)), height=(int(0.9/20.*win_height))),  0,1,1,1)   
        layout.addItem(self.proxyWidget(self.lbl_list2     , width=(int(1./10.*win_width)), height=(int(0.9/20.*win_height))),  0,2,1,1)  
        layout.addItem(self.proxyWidget(self.lbl_img_path  , height=(int(0.9/20.*win_height))),  0,3,1,20)  
        layout.addItem(self.proxyWidget(self.list_imgs     , width=(int(1./10.*win_width))),  1,1,20,1)   
        layout.addItem(self.proxyWidget(self.list_marks    , width=(int(1./10.*win_width))),  1,2,20,1)   
        layout.addItem(self.proxyWidget(self.btn_Next      , width=(int(1./10.*win_width))),  0+offset_grp_1,0)
        layout.addItem(self.proxyWidget(self.btn_Back      , width=(int(1./10.*win_width))),  1+offset_grp_1,0)
        layout.addItem(self.proxyWidget(self.btn_Predict_2D, width=(int(1./10.*win_width))),  2+offset_grp_2,0)
        layout.addItem(self.proxyWidget(self.btn_Predict_3D, width=(int(1./10.*win_width))),  3+offset_grp_2,0)
        layout.addItem(self.proxyWidget(self.btn_Pipeline  , width=(int(1./10.*win_width))),  4+offset_grp_2,0)
        layout.addItem(self.proxyWidget(self.btn_MarkPed   , width=(int(1./10.*win_width))),  5+offset_grp_3,0)
        layout.addItem(self.proxyWidget(self.btn_MarkCycl  , width=(int(1./10.*win_width))),  6+offset_grp_3,0)
        layout.addItem(self.proxyWidget(self.btn_MarkCar   , width=(int(1./10.*win_width))),  7+offset_grp_3,0)
        layout.addItem(self.proxyWidget(self.btn_Del_Mark  , width=(int(1./10.*win_width))),  8+offset_grp_3,0)
        layout.addItem(self.proxyWidget(self.btn_Rst       , width=(int(1./10.*win_width))),  9+offset_grp_3,0)
        layout.addItem(self.proxyWidget(self.btn_Save      , width=(int(1./10.*win_width))),  10+offset_grp_3,0)
        self.w.addItem(layout)
        self.setUp_pen_types()
        self.qt_connections()

结果看起来是这样的-尽管我希望在2D图像小部件下面有渲染的3D场景,背景颜色为黑色。你知道吗

GUI


Tags: selfwidthwinoffsetintpglayoutheight