环境:Qt5.3
IDE:QtCreator
效果预览:
垂直与水平滚动条样式
代码:
- ui->QTableView->verticalScrollBar()->setStyleSheet("QScrollBar:vertical{" //垂直滑块整体
- "background:#FFFFFF;" //背景色
- "padding-top:20px;" //上预留位置(放置向上箭头)
- "padding-bottom:20px;" //下预留位置(放置向下箭头)
- "padding-left:3px;" //左预留位置(美观)
- "padding-right:3px;" //右预留位置(美观)
- "border-left:1px solid #d7d7d7;}"//左分割线
- "QScrollBar::handle:vertical{"//滑块样式
- "background:#dbdbdb;" //滑块颜色
- "border-radius:6px;" //边角圆润
- "min-height:80px;}" //滑块最小高度
- "QScrollBar::handle:vertical:hover{"//鼠标触及滑块样式
- "background:#d0d0d0;}" //滑块颜色
- "QScrollBar::add-line:vertical{"//向下箭头样式
- "background:url(:/images/resource/images/checkout/down.png) center no-repeat;}"
- "QScrollBar::sub-line:vertical{"//向上箭头样式
- "background:url(:/images/resource/images/checkout/up.png) center no-repeat;}");
- ui->QTableView->horizontalScrollBar()->setStyleSheet("QScrollBar:horizontal{"
- "background:#FFFFFF;"
- "padding-top:3px;"
- "padding-bottom:3px;"
- "padding-left:20px;"
- "padding-right:20px;}"
- "QScrollBar::handle:horizontal{"
- "background:#dbdbdb;"
- "border-radius:6px;"
- "min-80px;}"
- "QScrollBar::handle:horizontal:hover{"
- "background:#d0d0d0;}"
- "QScrollBar::add-line:horizontal{"
- "background:url(:/images/resource/images/checkout/right.png) center no-repeat;}"
- "QScrollBar::sub-line:horizontal{"
- "background:url(:/images/resource/images/checkout/left.png) center no-repeat;}");
http://blog.csdn.net/shihoongbo/article/details/48970515