Search code examples
pythonpyqtpyqt5qcomboboxqtstylesheets

How to remove white background (on top and bottom) from popup of QComboBox?


I am creating a GUI app with qt5 and pyqt5. I am trying to create a dark theme but I've got a problem with QComboBox. When I tried to make a dark background on the QListView I get a white border or whatever its name on top and the bottom of the list.

I tried a lot of ways, like padding or marge changing of values but nothing helped I tried something mentioned already here Remove QListView background But always the same.

QComboBox {
    font: 12pt Fira Sans Condensed;
    background-color: #2e2e2e;
    border-top: 0px solid #3e3e3e;
    border-left: 0px solid #3e3e3e;
    border-right: 0px solid #3e3e3e;
    border-bottom: 2px solid #3e3e3e;
    padding: 5%;
    max-height: 30px;
    min-width: 140px;
    color: white;
    selection-background-color: #5e5e5e;
}

QComboBox::drop-down {
    border: none;
}

QComboBox::down-arrow {
    image: url(icons/QComboBox/down-arrow.png);
    width: 25px;
    height: 25px;
    border-width: 0px;
    padding-right: 10px;
}

QComboBox::down-arrow:pressed {
    position: relative;
    top: 1px; left: 1px;
}

QListView {
    font: 12pt Fira Sans Condensed;
    background-color: #2e2e2e;
    outline: 0;
    color: white;
    selection-background-color: #5e5e5e;
}

QListView::item {
    min-height: 20px;
    padding: 5%;
}
self.list = QtWidgets.QListView(self.window.comboBox)
self.window.comboBox.addItem("test1")
self.window.comboBox.addItem("test2")
self.window.comboBox.setView(self.list)

Here is what I get

Screenshot-2019-01-22-20-19-41.png

Screenshot-2019-01-22-20-20-08.png

Add I expect something without the white color on the top and bottom of the list


Solution

  • You have to set the color in the QFrame that is the parent of the view() directly:

    self.window.comboBox.view().parentWidget().setStyleSheet('background-color: #2e2e2e;')