Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Background Image Opacity & transparency
Forum Updated to NodeBB v4.3 + New Features

Background Image Opacity & transparency

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    shahriar25
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shahriar25
      wrote on last edited by
      #2

      Any help would be appreciated.

      1 Reply Last reply
      0
      • X Offline
        X Offline
        Xicor
        wrote on last edited by
        #3

        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).

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shahriar25
          wrote on last edited by
          #4

          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) {
              QListView::paintEvent(e);
          
              if (!backgroundImage.isNull())
              {
                  QPalette tempPalette;
                  tempPalette.setBrush(QPalette::Background, backgroundImage);
                  setPalette(tempPalette);
                  
                  //setBackgroundImage(backgroundImage);
              }
          }
          

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

          what am I doing wrong?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            shahriar25
            wrote on last edited by
            #5

            Any help would be appreciated.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved