[PyQt] Failure setting QListView background color

Damon Lynch damonlynch at gmail.com
Wed Mar 11 19:22:10 GMT 2015


On 03/11/2015 12:17 AM, Damon Lynch wrote:
> Hello all,
>
> What am I doing wrong below? If I comment out the setStyleSheet call , 
> and enable the palette changes, the background remains the default 
> white. The problem with using the setStyleSheet call is that it 
> affects the scrollbars inside the QListView too, which is not what I want.
>
> class ThumbnailView(QListView):
>     def __init__(self):
>         super(ThumbnailView, self).__init__(uniformItemSizes=True, 
> spacing=16)
>         self.setViewMode(QListView.IconMode)
>         # this next line works
>         self.setStyleSheet("background-color:#444444")
>         # these next three lines do not work when the lines are 
> uncommented:
>         # palette = self.palette()
>         # palette.setColor(self.backgroundRole(), QColor(68,68,68))
>         # self.setPalette(palette)
>
As a follow-up to my previous email, this is a screenshot illustrating 
the problem:
http://damonlynch.net/rapid/screenshots/beta/20150311rpd-devel-bg-color-failure.png

After the stylesheet change, the scrollbar looks much worse than the 
default. I'm new to Qt so I don't know if it is a bug in my code that 
the palette.setColor call fails, or the problem is elsewhere. In my 
previous message I neglected to mention I'm developing using python 
3.4.3, PyQT 5.4 & Qt 5.4 (on Ubuntu 15.04).

Incidentally if anyone is interested I'm using 0mq for high performance 
inter-process messaging, and udev, udisks2, and optionally GIO for 
mounting and unmounting hot-plugged devices like cameras and partitions. 
Maybe others could use the code too. It's GPL3. I'm currently porting 
the application from PyGTK. 
https://code.launchpad.net/~dlynch3/rapid/zeromq_pyqt

Best,
Damon

-- 

http://www.damonlynch.net

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150312/74c8f07d/attachment.html>


More information about the PyQt mailing list