12

I'm styling a QComboBox in Qt. It is rounded how the figure shows. The problem is that is shows a strange square box behind the rounded border.

Can someone tell me what this box is and how to make it invisible?

By the way, I'd like to take the shadow away too.

enter image description here

Here is my current code:

QComboBox {
    border: 1px solid gray;
    border-radius: 10px;
    min-width: 6em;
}

QComboBox:on {
    border-bottom-left-radius: 0px;
    border-bottom-right-radius: 0px;
}

QComboBox QAbstractItemView {
    border-bottom-right-radius: 10px;
    border-bottom-left-radius: 10px;
    background: white;
    border: 1px solid gray;
    box-shadow: transparent;
}

QComboBox::drop-down {
    border-color: transparent;
}

Can somebody help here?? Thanks!

jsidera
  • 1,791
  • 1
  • 17
  • 19

4 Answers4

2

you can add code behind like this,

(your qcombobox)->view()->window()->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);

i tried, it works

acraig5075
  • 10,588
  • 3
  • 31
  • 50
lily8561
  • 21
  • 3
  • 1
    can confirm, doesn't work for me either (Qt 5.12.3 on linux). if anyone has gotten it to work, I'm interested :) – pythonator May 15 '19 at 09:29
2

I think it will help you

QComboBox QAbstractItemView {
    border-bottom-right-radius: 10px;
    border-bottom-left-radius: 10px;
    background: white;
    border: 1px solid gray;
    box-shadow: transparent;
    padding: 4px 4px 4px 4px
}
2

Here's what worked for me with Qt 6.2 on Windows 11/macOS 12:

comboBox->setStyleSheet("QComboBox {"
                            "combobox-popup: 0;"
                            "background: transparent;"
                            "}");
comboBox->view()->setStyleSheet("QListView{"
                        "border:1px solid red;"
                        "border-radius: 8px;"
                        "}");
comboBox->view()->window()->setWindowFlags( Qt::Popup | Qt::FramelessWindowHint |Qt::NoDropShadowWindowHint);
comboBox->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
Robin Lobel
  • 630
  • 1
  • 5
  • 16
-4

Maybe you can provide some html, that would make it easier.

Try:

QComboBox{overflow:hidden}
acraig5075
  • 10,588
  • 3
  • 31
  • 50
Marc
  • 248
  • 2
  • 4
  • 15