6

By default, the QComboBox listview has shadow effect. Is there a way to remove it? Is the shadow controlled from QStyle or in some other way?

qcombobox shadow

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313

2 Answers2

4

The shadow effect is not a Qt specific thing, its a Desktop theme specific thing. The shadow depends on the style/theme your desktop environment is using. If your style/theme defines shadows for QComboBox then Qt will very promptly draw it. That said, you may search for a style that does not draw a shadow. I got the effect by doing so:

cb = QComboBox()
cb.addItems( [ '1', '2', '3', '4', '5', '6' ] )
cb.setStyle( QStyleFactory.create( "Polyester" ) )
cb.setStyleSheet( "QComboBox QAbstractItemView { border: 1 px solid gray; }" )
cb.show()

For this, you must have a compatible theme like polyester listed by QStyleFactory.keys(). I tried with the snazzy Breeze style and the famous QtCurve style, but they draws a shadow always. You may achieve the same using GTK+ and the Cleanlooks styles.

FYI: Polyester is one of the styles that comes with KDE.

Here is a screenshot of the above code:

enter image description here

Marcus
  • 1,685
  • 1
  • 18
  • 33
1

Okay, that might be working for someone who has themes without shadow effects but I have them, so I finally found a simple way to make it work.

self.comboBox.findChild(QFrame).setWindowFlags(Qt.Popup | Qt.NoDropShadowWindowHint)

combobox has one QFrame inside. Its window effect makes the shadow. We can erase that effect with the aforementioned line. Careful, don't put both, otherwise you won't open the popup.

I know it's been a while since this post was made but I haven't found any other solutions.

Philip Nelson
  • 1,027
  • 12
  • 28
Daegun Kim
  • 11
  • 1