QComboBox设置子项样式

来源:互联网 发布:数据挖掘可以做什么 编辑:程序博客网 时间:2024/06/10 08:26
    ui->setupUi(this);    ui->comboBox->setFixedHeight(45);//子项高度    QPixmap pixmap(1, ui->comboBox->height());    pixmap.fill(Qt::transparent);    QIcon icon(pixmap);    ui->comboBox->setIconSize(QSize(1,ui->comboBox->height()));    ui->comboBox->addItem(icon,"程序");    ui->comboBox->addItem(icon,"图形");    ui->comboBox->addItem(icon,"数据");    ui->comboBox->addItem(icon,"网络");    ui->comboBox->move(10,10);    QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();    ui->comboBox->setItemDelegate(itemDelegate);    ui->comboBox->view()->setFixedHeight(350);//设置下拉框总高度


qss::
QComboBox {
    border: 1px solid green;
    border-radius: 3px;
    padding: 1px 2px 1px 2px;
    min-width: 9em;
}
QComboBox::drop-down {
  subcontrol-origin: padding;
  subcontrol-position: top right;
  border-left-width: 1px;
  border-left-color: darkgray;
  border-left-style: solid; /* just a single line */
  border-top-right-radius: 3px; /* same radius as the QComboBox */
  border-bottom-right-radius: 3px;
}