gpt4 book ai didi

python - pyqtgraph.opengl VS OpenGL.GL - 如何在 PyQt5 OpenGL 嵌入式小部件中显示轴

转载 作者:行者123 更新时间:2023-12-01 01:21:29 27 4
gpt4 key购买 nike

如何使用pyqtgraph.opengl而不是OpenGL.GLPyQt5.QtWidgets openGLWidget交互?我需要在 PyQt5 表单上向 openGLWidget 进行下一个图形输出:

def plot_line(line):
pl_line = np.array(line)
color = (0.0, 0.0, 200.0, 0.5)
newline = gl.GLLinePlotItem(pos=pl_line, color=color, width=5, antialias=False)
w.addItem(newline)
w.show()

line1 = [(-33.13, 1004.82, -125.7), (21.38, 1059.32, -162.03)]
plot_line(line1)

这里我有一个示例,其中我有一个带有按钮和 openGLWidget 的 UI,我想将图形输出到我在 plot_line() 函数中定义的 openGLWidget。我应该如何执行这样的输出?

import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.uic import loadUi
import pyqtgraph.opengl as gl

class app_1(QDialog):
def __init__(self):
super(app_1,self).__init__()
loadUi('Qt_test_Ui.ui', self)
self.setWindowTitle('Test GL app')
self.pushButton.clicked.connect(self.on_push_b1)

@pyqtSlot()
def on_push_b1(self):
self.openGLWidget.paintGL = self.paintGL()


def paintGL(self):
w = self.openGLWidget
axis = gl.GLAxisItem() # show 3D axis
w.addItem(axis)


app=QApplication(sys.argv)
wid=app_1()
wid.show()
sys.exit(app.exec_())

最佳答案

QOpenGLWidget不是GLViewWidget所以你不能直接替换它。最接近的选项是您在 Qt Designer 中使用 GLViewWidget 使用升级,因为它右键单击 QOpenGLWidget 并选择选项“升级到...”,将打开以下对话框并使用以下值进行设置:

enter image description here

然后按“添加”和“升级”按钮。执行上述操作后生成的 .ui 如下:

Qt_test_Ui.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="GLViewWidget" name="openGLWidget"/>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>GLViewWidget</class>
<extends>QOpenGLWidget</extends>
<header>pyqtgraph.opengl</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

然后按以下方式使用:

import sys
from PyQt5 import QtCore, QtWidgets, uic
import pyqtgraph.opengl as gl

class app_1(QtWidgets.QDialog):
def __init__(self):
super(app_1,self).__init__()
uic.loadUi('Qt_test_Ui.ui', self)
self.setWindowTitle('Test GL app')
self.pushButton.clicked.connect(self.on_push_b1)

@QtCore.pyqtSlot()
def on_push_b1(self):
axis = gl.GLAxisItem()
self.openGLWidget.addItem(axis)

if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
wid=app_1()
wid.show()
sys.exit(app.exec_())

enter image description here

关于python - pyqtgraph.opengl VS OpenGL.GL - 如何在 PyQt5 OpenGL 嵌入式小部件中显示轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53798877/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com