声明:本文章内容,仅仅是为了方便自己以后回来查看,因此会持续更新,不断收录!
一、QTabWidget
QTabWidget::pane{
border-width:1px;
border-style:solid;
border-color:rgb(1, 124, 217);
background:transparent;
}
QTabWidget::tab-bar{
alignment:left;
}
QTabBar::tab{
/*background-color: rgb(1, 124, 217); */ /*浅蓝色*/
background-color: rgb(4, 116, 191); /*深蓝色*/
color:white;
min-width:30px;
min-height:10px;
border: 0px;
padding:5px;
}
QTabBar::tab:selected{
border-color: white;
background-color: rgb(238, 159, 0); /*橘黄色*/
color:white;
}
QTabBar::tab:!selected {
margin-top: 5px;
}
效果如下:
二、QTableWidget以及QScrollBar
QTableWidget
{
color:black; /*前景色:文字颜色*/
/*gridline-color:red; */ /*表格中的网格线条颜色*/
background:white;
/*设置交替颜色,需要在函数属性中设置:tableWidget->setAlternatingRowColors(true)*/
alternate-background-color:rgb(211, 211, 211);
/*border:1px solid gray;*/ /*边框线的宽度、颜色*/
border:none; /*去除边界线*/
}
/*设置表头属性*/
QHeaderView::section {
background-color: rgb(4, 116, 191); /*蓝色*/
color: white;
padding-left: 4px;
border:none; /*去除边界线*/
}
/******************************************************/
另外代码里设置好QTableWidget的其他属性:
void EventRecordDlg::initTableWdgt(QTableWidget* tableWidget,int hWidth1,int hWidth2,int hWidth3,int hWidth4)
{
/*!
* 设置编辑框的垂直滑动条的样式
* (注意,此处QSS设置效果在设计器里手动设置代码运行时无效果)
*/
QString str = "QScrollBar:vertical{max-width: 18px;background-color: transparent;padding-top: 19px;padding-bottom: 19px;}"
"QScrollBar::handle:vertical {width: 18px;min-height: 40px;background-color: rgb(4, 116, 191); /*深蓝色*/}"
"QScrollBar::handle:vertical:hover {background-color: rgb(238, 159, 0); /*橘黄色*/}"
"QScrollBar::sub-line:vertical {height: 18px;width: 18px;background-color: rgb(0, 136, 204);subcontrol-position: top;}"
"QScrollBar::add-line:vertical {height: 18px;width: 18px;background-color: rgb(0, 136, 204);subcontrol-position: bottom;}"
"QScrollBar::sub-line:vertical:hover {background-color: rgb(238, 159, 0); /*橘黄色*/}"
"QScrollBar::add-line:vertical:hover {background-color: rgb(238, 159, 0); /*橘黄色*/}"
"QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical {background: rgb(220, 220, 220);}";
tableWidget->setColumnCount(5);
tableWidget->horizontalHeader()->setVisible(true);
tableWidget->verticalHeader()->setVisible(false);
tableWidget->setColumnWidth(0,hWidth1);
tableWidget->setColumnWidth(1,hWidth2);
tableWidget->setColumnWidth(2,hWidth3);
tableWidget->setColumnWidth(3,hWidth4);
tableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers); //设置表格无法编辑
tableWidget->setSelectionMode(QAbstractItemView::NoSelection); //设置表格无法选择
tableWidget->setAlternatingRowColors(true); //设置表格允许行交替颜色
tableWidget->horizontalHeader()->setHighlightSections(false); //解决表头塌陷问题:点击表格时不对表格行光亮(获取焦点)
//tableWidget->setItemDelegate(new NoFocusDelegate(this->parent())); //解决鼠标点击的选项会出现虚框问题,此处NoFocusDelegate是自定义的类
tableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section {background-color: rgb(4, 116, 191);"
"color: white;padding-left: 4px;border: none;}");
tableWidget->verticalScrollBar()->setStyleSheet(str);
tableWidget->verticalScrollBar()->scroll(40, 20);
tableWidget->horizontalHeader()->setDisabled(true);
tableWidget->horizontalHeader()->setSectionsMovable(false);
tableWidget->horizontalHeader()->setSectionsClickable(false);
tableWidget->hideColumn(4); //隐藏第五行,事件码event id
}
运行效果如下:
三、QComboBox
QComboBox {
border: 1px solid gray;
/*border-radius: 3px;*/
padding: 1px 2px 1px 2px; /*针对于组合框中的文本内容*/
/*min-width: 9em;*/ /*组合框的最小宽度*/
}
QComboBox::drop-down {
subcontrol-origin: padding;
subcontrol-position: top right;
/*width: 20px;*/
border-left-width: 1px;
border-left-color: darkgray;
border-left-style: solid;
/*border-top-right-radius: 3px;
border-bottom-right-radius: 3px;*/
background-color: rgb(234, 234, 234);
}
QComboBox::down-arrow {
border-image: url(:/HTP_Images/images/img_arrow1.png);
}
运行效果如下:
四、QPushButton
QPushButton
{
color: rgb(255, 255, 255);
border-image: url(:/HTP_Images/images/im_btnNoSelect.png);
border:none;
padding: 5px;
outline: none;
}
QPushButton:pressed
{
border-image: url(:/HTP_Images/images/im_btnSelect.png);
padding-top: -15px;
padding-bottom: -17px;
}
运行效果如下:
五、QLineEdit
QLineEdit{
border: 1px solid gray;
padding: 1px 2px 1px 2px;
}
QLineEdit:hover{
border:1px solid blue;
background-color: rgb(85, 255, 0);
}
运行效果如下:
六、QGroupBox
QGroupBox{
border: 1px solid rgb(1, 124, 217);;
border-radius: 4px;
margin-top: 7px;
}
QGroupBox::title {
subcontrol-origin: margin;
subcontrol-position: top left;
left:14px;
padding: 0 5px;
}
运行效果如下: