1.在 QComboBox
的父 Widget 中設置 QComboBox
的樣式
QComboBox{
background-color: rgb(255, 255, 255);
border:1px solid rgb(221,221,221);
font: 10pt "微軟雅黑";
padding-left:10px;
}
QComboBox QAbstractItemView::item{
height:30px;
}
QComboBox::down-arrow{
image: url(:/login/icon_down);
}
QComboBox::drop-down{
width:20px;
border:none;
}
2.在 Widget
窗口類的構造函數中設置 QComboBox
子項代理,並設置 QAbstractItemView
樣式
QStyledItemDelegate *delegate = new QStyledItemDelegate(this);
ui.comboBox->setItemDelegate(delegate);
ui.comboBox->setStyleSheet("QComboBox QAbstractItemView {border:1px solid #dddddd;outline:0px;height:30px; } QComboBox QAbstractItemView::item {min-height: 30px;background-color: rgb(255, 255, 255);color:#333;padding-left:11px;outline:0px;} QComboBox QAbstractItemView::item:hover {color:#333;background-color: #e9f2ff;}");