Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QComboBox cannot make dropdown window background transparent
Forum Updated to NodeBB v4.3 + New Features

QComboBox cannot make dropdown window background transparent

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 547 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • EchoReaperE Offline
    EchoReaperE Offline
    EchoReaper
    wrote on last edited by EchoReaper
    #1

    I've tried everything I could to make the QComboBox window background transparent, but it just shows up black:
    86df0d27-0c68-443d-b085-fc000d244cde-image.png

    I am using Qt 5.12.9 on Windows 10. The QComboBox's stylesheet is

    * {
        padding: 10px 10px 10px 10px;
        border-radius: 10px; 
    }
    

    and in mainwindow.cpp in a brand new, empty Qt project (with just the combobox added and mainwindow background set to red for visibility):

        ui->comboBox->setFrame(false);
        QFrame* window = dynamic_cast<QFrame*>(ui->comboBox->view()->window()); // this is a QComboBoxPrivateContainer, which is a subclass of QFrame
        window->setFrameStyle(QFrame::NoFrame);
        window->setStyleSheet("* { background-color: green; }");
        window->setWindowFlags(Qt::FramelessWindowHint);
        window->setAttribute(Qt::WA_TranslucentBackground, true);
        window->setAttribute(Qt::WA_OpaquePaintEvent, true);
    

    Yet the window background is still black. Further, FramelessWindowHint prevents the dropdown from opening unless I press space with it focused (and after opening, it immediately closes)

    How do I make the dropdown window background completely invisible for QComboBox?

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @EchoReaper said in QComboBox cannot make dropdown window background transparent:

      window->setFrameStyle(QFrame::NoFrame);
      window->setStyleSheet("* { background-color: green; }");
      

      add "QAbstractItemView{background:green;}" to the stylesheet of ui->comboBox .

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved