Qt工作笔记-QSS中关于QCombox的设置

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq78442761/article/details/81983316

QSS源码如下:

QComboBox {
border: 1px solid rgb(0, 0, 0);
border-radius: 3px;
padding: 1px 18px 1px 3px;
min-width: 6px;
background-color: rgb(0, 195, 255);
color: rgb(255, 255, 255);
font: 14pt "华文琥珀";
}

运行截图如下:

注意:这里font的大小会影响padding的属性(在QSS里面,很多属性会互相影响,这是要注意的)

修改向下的那个箭头,和修改箭头旁边领域中的样式:

QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
width: 16px;
border-left-width: 1px;
border-left-color: darkgray;
border-left-style: solid;
border-top-right-radius: 3px; 
border-bottom-right-radius: 3px;
}

QComboBox::down-arrow {
image: url(:/img/arrows_down.png);
}

程序运行截图如下:

设置下拉选项框里面。选项框里面的属性,源码如下:

QComboBox QAbstractItemView
{
border: 1px solid rgb(161,161,161);
}
 
QComboBox QAbstractItemView::item
{
height: 24px;
color: rgb(255, 255, 255);
background-color: rgb(0, 195, 255);
}
 
QComboBox QAbstractItemView::item:selected
{	
background-color:rgb(22, 37, 124);
}


运行截图如下:

这里要注意:

QComboBox并没有专门设置内部Item的QSS,要使用这样的代码:

    QStyledItemDelegate* itemDelegate = new QStyledItemDelegate();
    ui->comboBox->setItemDelegate(itemDelegate);

今晚将会对QStyledItemDelegate进行补充

猜你喜欢

转载自blog.csdn.net/qq78442761/article/details/81983316