Important: Please read the Qt Code of Conduct -

Background Image Opacity & transparency

  • Hi, I'm working on a music player and I want the QListView that shows the tracks in album to have the album's cover art as it's background with for example 50% opacity and transparency so the Items and the window's stylesheet can be seen. this is how I set the background now:

    ui->trackView->setStyleSheet(QString("background-image: url(%1)").arg(QString().append(coverArtPath).append(album.attribute("title"))));

    What should I do?

  • Any help would be appreciated.

  • so you want the listview to have a background or you want each row to have a background? for the latter you would create your own delegate (subclass qstyleditemdelegate) and implement the paint function, for the former, you would want to subclass listview and implement the paint function(painting the background and then calling the parent paint).

  • Hi, @Xicor
    I want the listview to have a background. I did what you said but it's not working (evet the commented part) :

    class TrackView : public QListView
    QPixmap backgroundImage;

    void paintEvent(QPaintEvent *e) {
        if (!backgroundImage.isNull())
            QPalette tempPalette;
            tempPalette.setBrush(QPalette::Background, backgroundImage);

    TrackView(QWidget* parent = 0) : QListView(parent) {}
    void setBackgroundImage(QPixmap image) { backgroundImage = image; }

    what am I doing wrong?

  • Any help would be appreciated.

Log in to reply