title: Individual background color of a QListWidget-item on selection
body: <p>I have a list of indidually colored items in a QListWidget as part of a Python3/PySide application. On selection, I would like the items being highlighed using some color while maintaining their respective background, i.e.</p>
  
  <p><img src="https://i.stack.imgur.com/HQJNa.png" alt="desired display"></p>
  
  <p>and not a full-colored version as depicted in the following image</p>
  
  <p><img src="https://i.stack.imgur.com/dUtmc.png" alt="current display"></p>
  
  <p>The items which are mainly distinguished by means of the colors (background or not) are rearrangable using dragging. It is important for a user to be able to always see what the current selection is.</p>
  
  <p>Using <code>selection-color: solid rgba(255, 0, 0, 50%);</code> does not show the desired effect.</p>
  
  <p>I'm not sure how the aspects discussed in <a href="https://stackoverflow.com/questions/18035707/selected-qlistwidgetitem-without-changing-text-color">SO:Selected QListWidgetItem without changing text color</a> and even more <a href="https://stackoverflow.com/questions/7274806/how-to-customize-qlistwidget-with-different-highlight-bar-and-spacing">How to customize QListWidget with different highlight bar and spacing</a> may apply to my problem. Is it really necessary to add another Widget on top of the list? Is there a way to apply a different brush to an item on selection (using <code>PySide.QtGui.QListWidgetItem.setBackground(brush)</code>)? The stylesheets do not seem to help in my case.</p>
  
  <p>Here is the condensed code:</p>
  
  <pre><code>import sys
  import collections
  from PySide import QtCore, QtGui
  
  class MainWindow(QtGui.QWidget):
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          #definition of colors and brushes (for colored backgrounds)
          layers = collections.OrderedDict(
              {1:('greenItem','g'),
               2:('yellowItem','y'),
               3:('mixedItem','m')})
          brushes = {'y': QtGui.QColor(255,200,0),
                     'g': QtGui.QColor(0,  160,0)}
          texSIG = QtGui.QPixmap(200,1)
          texSIG.fill(brushes['g'])
          paint = QtGui.QPainter()
          paint.begin(texSIG)
          paint.fillRect(80, 0, 40, 1, brushes['y'])
          paint.end()
          brushes['m'] = texSIG
          #create list
          self.lst = QtGui.QListWidget(self)
          self.lst.setStyleSheet( """
                                  QListWidget:item:selected:active {
                                       background-color:red;
                                  }
                                  """
                                  )
          #comment on styling:
          #background-color on selection is plain red
          #something like "selection-color: solid rgba(255, 0, 0, 50%);" shows no effect
  
          self.lst.setSortingEnabled(False)
          for idx, d in layers.items():
              newItem = QtGui.QListWidgetItem('{:s}'.format(d[0]))
              newItem.setBackground(QtGui.QBrush( brushes[d[1]] ))
              newItem.setTextAlignment(QtCore.Qt.AlignVCenter)
              self.lst.addItem(newItem)
          self.lst.setSelectionMode(QtGui.QAbstractItemView.SelectionMode(QtGui.QAbstractItemView.ExtendedSelection))
          self.lst.setDragDropMode(self.lst.InternalMove)
          #setup and show window
          self.setMinimumWidth(200)
          self.setMinimumHeight(200)
          self.show()
  #create gui
  app = QtGui.QApplication(sys.argv)
  #create and display main window
  main = MainWindow()
  main.show()
  #return exit code
  sys.exit(app.exec_())
  </code></pre>