Python Forum
Help with pyqtgraph
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with pyqtgraph
#1
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)
Reply
#2
From the documentation:

https://pyqtgraph.readthedocs.io/en/late...m.setImage
Quote:Parameters
:
image (numpy.ndarray or None, default None) – Image data given as NumPy array with an integer or floating point dtype of any bit depth. A 2-dimensional array describes single-valued (monochromatic) data. A 3-dimensional array is used to give individual color components. The third dimension must be of length 3 (RGB) or 4 (RGBA). np.nan values are treated as transparent pixels.
It does not say that image can be a QPixmap. You can get a pixel array from a QImage, and you can get a QImage from a QPixmap, but this is painful. Since you just want a numpy ndarray of pixels, I would use pillow and numpy.
pixels = numpy.asarray(PIL.Image.open("image_file.png"))
keithchee1 likes this post
Reply
#3
Thank you so much for the help!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  plotting 2d and 3d using pyqt5 and pyqtgraph and GLSurfacePlotItem kiyoshi7 1 8,924 Jan-20-2020, 12:13 AM
Last Post: kiyoshi7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020