我想在我的应用程序中的一个量规中显示一些数据。我正在使用pyqt5。
我正在创建一个canvas,其中将显示我的图块或计量器(某个时候是一个图,另一个是一个量规):
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=8, height=6, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.axes = fig.add_subplot(111)
super(MplCanvas, self).__init__(fig)并将这个canvas添加到我的主布局中:
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.canvas = MplCanvas(self, width=12, height=8, dpi=100)
self.layout_plot.addWidget(self.canvas)
self.show()我在如何创建量规上找到了一个链接
import PIL
from PIL import Image
percent = 20 # Percent for gauge
output_file_name = 'new_gauge.png'
percent = percent / 100
rotation = 180 * percent # 180 degrees because the gauge is half a circle
rotation = 90 - rotation # Factor in the needle graphic pointing to 50 (90 degrees)
dial = Image.open('needle.png')
dial = dial.rotate(rotation, resample=PIL.Image.BICUBIC, center=loc) # Rotate needle
gauge = Image.open('gauge.png')
gauge.paste(dial, mask=dial) # Paste needle onto gauge
gauge.save(output_file_name)我试图以这种方式将gauge添加到我的“画布”中:
dial = Image.open('needle.png')
dial = dial.rotate(rotation, resample=PIL.Image.BICUBIC, center=loc) # Rotate needle
gauge = Image.open('gauge.png')
gauge.paste(dial, mask=dial) # Paste needle onto gauge
self.layout_plot.removeWidget(self.canvas)
self.layout_plot.addWidget(gauge)
self.canvas.draw()我知道这个错误:
TypeError: addWidget(self, QWidget, stretch: int = 0, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'PngImageFile'如何将此gauge添加到我的canvas中
发布于 2020-07-28 16:47:06
您的问题令人困惑,因为如果对您指出的内容进行了分析,则可以将其解释为:
https://stackoverflow.com/questions/63138735
复制相似问题