QComboBox样式

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);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值