QComboBox 美化

在这里记录工作中美化下拉框的qss代码,以便以后忘记,方便自己找到:

QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
    QComboBox   *comboBox = new QComboBox();
    comboBox->setItemDelegate(itemDelegate);       //这里既可以用迭代

 //   comboBox->setView(new QListView());            //也可以用listView实现
    comboBox->insertItem(0, QString::fromWCharArray(L"备份所有文件"));
    comboBox->insertItem(1, QString::fromWCharArray(L"排除所选文件类型"));
    comboBox->insertItem(2, QString::fromWCharArray(L"包含所选文件类型"));

    comboBox->setStyleSheet(
        "QComboBox QAbstractItemView{border:1px solid rgb(156,176,201);}"
        "QComboBox QAbstractItemView::item{width:200px;height:30px;}"
        "QComboBox{width:200px;;height:30px;font-family:MicrosoftYaHei; font-size: 12px;color:rgb(26,26,26);padding-left:10px;border:1px solid rgb(134,166,209);border-image:url(:/TestWidget/Resources/combobox/Drop_down_box_280_normal.png);}"
         "QComboBox::hover{border-image: url(:/TestWidget/Resources/combobox/Drop_down_box_280_hover.png)}"
         "QComboBox::pressed{border-image: url(:/TestWidget/Resources/combobox/Drop_down_box_280_click.png)}"
         "QComboBox:drop-down{subcontrol-origin: padding;subcontrol-position: center right;image:url(:/TestWidget/Resources/combobox/icon_Drop_down_arrow_normal.png);}"
         "QComboBox:drop-down:hover{image:url(:/TestWidget/Resources/combobox/icon_Drop_down_arrow_hover.png);}"
        "QComboBox:drop-down:pressed{image:url(:/TestWidget/Resources/combobox/icon_up_arrow_hover.png);}"
        "QListView::item{font-family:\"Helvetica\"; font:12px;color:rgb(26,26,26);}"
        "QListView::item:selected:active{background:rgba(161,198,242,0.3);}"
        );


    QHBoxLayout *maillaout = new QHBoxLayout(this);
    maillaout->setContentsMargins(0, 0, 0, 0);
    maillaout->setSpacing(0);
    maillaout->addWidget(comboBox);
    maillaout->addStretch();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值