Qt样式表:QComboBox的弹出列表样式

QComboBox的弹出列表的类型是QAbstractItemView。这是个抽象类,无法创建对象,如果QComboBox自定义弹出列表类型使用的是它的子类,一般是QListView。当然用其他子类也行,如:

    ui->comboBox->setView(new QTreeView());

Qt样式表:QComboBox的弹出列表样式

就是看起来怪怪的。

弹出列表参考样式:

QComboBox{
    border-radius: 6px;
    border: 1px solid #00bcd4;
    padding:6px 10px 6px 10px;
    color: #000000;
}
QComboBox::drop-down{
    border:none;
}
QComboBox::down-arrow{
    image: url(:xiala_black.png);border: none;
}
QComboBox:disabled{
    background: #d8d8d8;
}
QComboBox QAbstractItemView{
    background-color: #FFFFFF;
    color:#000000;
    border:1px solid #00bcd4;
    border-radius:6px;
    outline:none;
}
QComboBox QAbstractItemView::item{
    selection-background-color: #00bcd4;
    color:#000000;
    height:40px;
    border-radius:6px;
}
QComboBox QAbstractItemView::item:selected{
    background-color: #00bcd4;
    color:#FFFFFF;
}
QComboBox QScrollBar::vertical{
    width:10px;
    background-color:transparent;
    border:none;
    border-radius:6px;
}
QComboBox QScrollBar::handle::vertical{
    border-radius:6px;
    width: 10px;
    background:#00bcd4;
}
QComboBox QScrollBar::handle::vertical::hover{
    background:#24d4e0;
}
QComboBox QScrollBar::add-line::vertical{
    border:none;
}
QComboBox QScrollBar::sub-line::vertical{
    border:none;
}

QComboBox要设置setView()弹出列表样式才会起作用:

    ui->comboBox->setView(new QListView());

设置弹出菜单圆角:

    QListView * list_combox = new QListView();
    ui->comboBox->setView(list_combox);
    ui->comboBox->view()->window()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint|Qt::NoDropShadowWindowHint);
    ui->comboBox->view()->window()->setAttribute(Qt::WA_TranslucentBackground);
    ui->comboBox->view()->window()->setCursor(Qt::PointingHandCursor);

效果:

Qt样式表:QComboBox的弹出列表样式

上一篇:Linux&imx6ull 使用QT开发串口工具(完整版)


下一篇:TCP/IP网络编程 读书笔记1