How to set QComboBox menu background transparent?
-
I'm trying to create a combo box with rounded borders including the pop-up menu, but when I set a border-radius, it doesn't apply to the background:
While searching for a way to remove this background, I found this answer: https://stackoverflow.com/questions/27962162/rounded-qcombobox-without-square-box-behind
To reproduce:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { ui.setupUi(this); QComboBox* comboBox = new QComboBox(this); comboBox->setStyleSheet(R"( QComboBox { border-radius: 8px; margin: 10px; background-color: gray; min-height: 32px; } QComboBox QAbstractItemView { border-radius: 8px; margin: 10px; background-color: gray; } )"); comboBox->move(100, 100); comboBox->addItem("1"); comboBox->addItem("2"); comboBox->view()->window()->setWindowFlags( Qt::Popup | Qt::FramelessWindowHint |Qt::NoDropShadowWindowHint); comboBox->view()->window()->setAttribute(Qt::WA_TranslucentBackground); }
It does remove the background, but it lets a black background visible for a short:
How can I get rid of this black background?
Here's everything I already tried that didn't work:
if (comboBox->view()->parentWidget()) { auto p = comboBox->view()->parentWidget(); p->setWindowOpacity(0); p->setWindowFlags( Qt::Popup | Qt::FramelessWindowHint |Qt::NoDropShadowWindowHint); p->setAttribute(Qt::WA_TranslucentBackground); p->setHidden(true); p->setAutoFillBackground( false ); } comboBox->setAutoFillBackground( false ); comboBox->view()->setAutoFillBackground( false ); comboBox->view()->viewport()->setAutoFillBackground(false); comboBox->view()->window()->setAutoFillBackground(false); //comboBox->view()->setAttribute(Qt::WA_TranslucentBackground); //comboBox->view()->viewport()->setAttribute(Qt::WA_TranslucentBackground); //comboBox->view()->window()->setAttribute(Qt::WA_TranslucentBackground); comboBox->view()->setWindowOpacity(0); comboBox->view()->viewport()->setWindowOpacity(0); comboBox->view()->window()->setWindowOpacity(0); //comboBox->view()->setHidden(true); //comboBox->view()->viewport()->setHidden(true); //comboBox->view()->window()->setHidden(true); QPalette palette = comboBox->view()->palette(); palette.setColor(QPalette::Window, Qt::transparent); comboBox->view()->setPalette(palette);
The unique thing i didn't tried yet is using a proxy as i have no experience with it.
Does someone has any idea if twerking into proxy it could be possible to get ride of that black window that appears for a short?
-
@Roberrt said in How to set QComboBox menu background transparent?:
I couldn't even find a way to get a pointer to that window
What window do you mean?
-
@Roberrt said in How to set QComboBox menu background transparent?:
I couldn't even find a way to get a pointer to that window
What window do you mean?