QT界面技巧-QComboBox的QSS设置

1,218 阅读1分钟

QT界面技巧-QComboBox的QSS设置

如需转载请标明出处 QQ技术交流群:129518033

环境:
QT版本:5.6.2
操作系统:windows 7 64bit

1.QComboBox设置下拉框item高度

/*global QComboBox height*/
QComboBox QAbstractItemView::item {
    height: 50px;
}

注意:在QSS中设置完后,需要调用如下代码,否则会使用默认的item样式,导致设置无效

    //if no this code, the style sheet wont be applied to the default combobox item view.
    ui->comboBox->setView(new  QListView());

默认样式:
这里写图片描述
修改后样式:
这里写图片描述

##2.QComboBox设置下拉框item的字体大小

/*global QComboBox font size*/
QComboBox QAbstractItemView{
    font-size: 18px;
}

注意:在QSS中设置完后,需要调用如下代码,否则会使用默认的item样式,导致设置无效

    //if no this code, the style sheet wont be applied to the default combobox item view.
    ui->comboBox->setView(new  QListView());

默认样式:
这里写图片描述
修改后样式:
这里写图片描述