[PyQt] question about QComboBox

Dave Gradwell davegradwell at yahoo.co.uk
Thu Apr 7 23:37:54 BST 2016


Hi Phillip,

> Worse yet, the API documentation does not mention a setStyleSheet method
QComboBox inherits setStyleSheet() from QWidget (where it may be better documented) so this should work:
QtWidgets.QComboBox(parent).setStyleSheet("color:red;”)

You may be able to style individual items by manipulating the Painter:
http://stackoverflow.com/questions/516032/how-to-make-qcombobox-painting-item-delegate-for-its-current-item-qt-4
A bit lower-level, but helped me achieve something similar when I needed to go beyond style-sheeting..

Best, Dave.


> On 7 Apr 2016, at 21:58, Phillip Feldman <phillip.m.feldman at gmail.com> wrote:
> 
> In Qt4 (or at least in PyQt4), it was possible to set a stylesheet for a QComboBox, but not possible to set styles on individual options/items in a QComboBox.  I was hoping that this would be addressed in Qt5, but it hasn't.  Worse yet, the API documentation does not mention a setStyleSheet method, so it looks as though the ability to set a stylesheet for the top-level widget has been removed.  I hope that I'm wrong on both of these points.
> 
> Phillip



More information about the PyQt mailing list