Jul-31-2024, 08:42 AM
Good day everyone, I am trying to design a vehicle dashboard on python that receives data such as voltage, speed, and current via UART from another microcontroller. This data will then be parsed and used to dynamically update the dashboard. I have managed to implement the UART portion but am struggling with designing the dashboard. I want to use a certain PNG image with QPixmap as my base for the speedometer widget so that I will be able to add a needle using pyqtgraph. I have tried implementing it with Qlabel and it works but when I try to use setImage from pyqtgraph, it says that QPixmap has no 'view' attribute. Below is a portion of the code where I try to implement a speedometer. Any help would be appreciated as I am new to python and have come from C. Thank you!
import sys
import numpy as np
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QFrame
from PyQt5.QtCore import QTimer
import pyqtgraph as pg
from PyQt5.QtGui import QPixmap, QPen, QFont
class CarDashboard(QWidget):
def __init__(self):
super().__init__()
# ... other code
# Create speedometer
self.speedometer = pg.PlotWidget()
speedometer_background = pg.ImageItem()
speedometer_background_image = QPixmap('C:/Users/Bob/Documents/Backup/PBX Cluster Project/Cluster Elements/RPM.png')
[error]speedometer_background.setImage(speedometer_background_image)[/error]
speedometer_background.setPos(15, 108)
self.rpm_meter.addItem(speedometer_background)
