1

EDIT: Edited to ask one question instead of 2 plus clarification.

I have found similar solutions such as this (printed below) for adding an image background to a widget, but this example is for QLabel. I am trying to add an image to QListWidget which does not have a setpixmap() method as suggested in the example. I am trying to set an image as the background on the ListWidget just like I would set a background-color to a color.

import sys
from PySide2 import QtCore, QtGui, QtWidgets

app = QtWidgets.QApplication(sys.argv)

pixmap = QtGui.QPixmap('/Users/mymac/Downloads/ecg_measure.png')
label = QtWidgets.QLabel()
label.setPixmap(pixmap)    
label.show()

app.exec_()

Unfortunately, the docs for PySide2 are not very helpful and assume the reader already knows all the details they skip over. I tried using various methods from parent classes, but have no guide for the syntax, and nothing workded yet.

zzr99
  • 78
  • 5
  • if you get error message then why don't you show it. We can't run your code, we can't see your screen, and we can't read in your mind. Don't expect magic. To get help you have to add all information in question (not in comment). – furas May 17 '19 at 08:56
  • What kind of widget do you want to set the image as a background? – eyllanesc May 17 '19 at 08:57
  • Hi again :) I am trying to set image as background for QListWidget and a different image for the background of the rest of my app - the space outside all the widgets. I'm not sure if that would fall under QApplication or QWidget...? – zzr99 May 17 '19 at 09:17
  • @furas I have included the traceback for the code I posted. As for adding an image to QListWidget, I already posted the link to what I tried and explained that there is no setPixmap method for QListWidget. That solution works only for QLabel. – zzr99 May 17 '19 at 09:56
  • @zzr99 In a QLabel it is very easy to know where to place the image, but in a QListWidget it is somewhat confusing: Do you want to place the image in each item or where? – eyllanesc May 19 '19 at 04:51
  • I am trying to set the image as a background in the QListWidget instead of setting 'background-color: color_choice'. Thanks – zzr99 May 20 '19 at 08:45

0 Answers0