2016-12-04 941 views
0

我想绘制红色组合框的背景,当它关闭时如果没有选择并且在选择时回到白色。 列表部分应始终为白色,但编辑器部分(顶部)在空白时应为红色,在选择项目时应为白色。QCombobox编辑部分组合框的背景颜色

回答

0
Found the solution: 

    QPalette pal = Combo->palette(); 
    pal.setColor(QPalette::Base, QColor(Qt::red)); 
    Combo->setPalette(pal); 

    For each item of Combo: 

    Combo->insertItem(index, z); 
    Combo->setItemData(index, QColor(Qt::white), Qt::BackgroundColorRole); 

after all the items added: 
Combo->setCurrentIndex(-1);