qss设置
QComboBox
{
font:32px;
height: 89px;
border:none;
background: rgb(23,53,59);
}
QComboBox:hover, QComboBox:focus
{
background: rgb(20,162,182);
}
QComboBox::drop-down
{
width: 58px;
border:none;
}
QComboBox::down-arrow
{
image: url(:/images/arrow_retract_icon.png);
}
QComboBox::down-arrow:on
{
image: url(:/images/arrow_open_icon.png);
}
QComboBox QAbstractItemView
{
border: none;
outline:none;
background-color:rgb(23,53,59);
selection-background-color:rgb(20,162,182);
}
/*选项的高度*/
QComboBox QAbstractItemView::item
{
height: 89px;
}
但是这样设置之后,选项的高度依旧没有变化,大概是这样:
如何设置 QComboBox的下拉框Item高度呢?其实在代码中再加入如下代码即可:
ui->comboBox->setView(new QListView(this));
在qss中再设置一下选项的字体:
QComboBox QAbstractItemView
{
font:32px light;
}
这时候的效果:
另外,设置选项文字居中可以用以下代码实现,但是QComboBox本身的文字并没有居中,于是放弃,这里只是记录一下:
for(int i = 0;i < ui->comboBox->count();++i){
static_cast<QStandardItemModel*>(ui->comboBox->view()->model())->item(i)->setTextAlignment(Qt::AlignCenter);
}