0
我想繪製紅色組合框的背景,當它關閉時如果沒有選擇並且在選擇時回到白色。 列表部分應始終爲白色,但編輯器部分(頂部)在空白時應爲紅色,在選擇項目時應爲白色。QCombobox編輯部分組合框的背景顏色
我想繪製紅色組合框的背景,當它關閉時如果沒有選擇並且在選擇時回到白色。 列表部分應始終爲白色,但編輯器部分(頂部)在空白時應爲紅色,在選擇項目時應爲白色。QCombobox編輯部分組合框的背景顏色
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);