Qt中各个控件利用Qt Designer来setStyleSheet

1.QLabel  

QLabel#label_sum_text{

font: 75 35pt "微软雅黑"; /*字体*/

background-color: rgb(255, 255, 255); /*背景色*/

color: rgb(152, 156, 156); /*字体颜色*/

border-style:hidden; /*边框样式*/

padding: 1px 1px 8px 1px;  /*四周边距*/

}


2.QToolButton、QPushButton

/*按钮正常显示*/

QToolButton#toolButton_7{

border-image: url(

:/keybord_cfm/images/keybord_cfm/u63.png);

}


/*按钮按下*/

QToolButton#toolButton_7::pressed{

border-image: url(

:/keybord_cfm/images/keybord_cfm/u63_mouseOver.png);

}


/*鼠标移到按钮上时*/

QToolButton#toolButton_7::hover{

border-image: url(

:/keybord_cfm/images/keybord_cfm/u63_mouseOver.png);

}

注意:border-image适用于所有控件

3.QFrame

QFrame#frame_right_top{

border-style:solid; /*边框样式*/

border-width:1px; /*边框宽度*/

border-radius: 6px; /*圆角边框*/

border-color: rgb(173, 176, 182); /*边框颜色*/

background-color: rgb(255, 255, 255); /*背景色*/

}

4.QTableView

/*设置行交替颜色*/

QTableView::item:alternate:!selected,

QTableWidget::item:alternate:!selected,

QListView::item:alternate:!selected

{ background: rgb(255, 255, 204); }

QTableView::item:!alternate:!selected,

QTableWidget::item:!alternate:!selected,

QListView::item:!alternate:!selected

{ background: rgb(248, 236, 212); }


QTableView{

font: 11pt "微软雅黑";

color: rgb(152, 152, 152);

selection-background-color: rgb(50, 151, 243);

}


QTableView::item:selected{

color: rgb(152, 152, 152);

background:rgb(248, 236, 212); /*选中行背景色*/

}


/*表头设置*/

QTableView QHeaderView

{

background-color: rgb(248, 248, 248);

font: 12pt "微软雅黑";

color: rgb(112, 112, 112);

}


/*水平表头*/

QHeaderView::section::horizontal {

padding: 0px;

border: none;

border-bottom: 1px solid rgb(214, 215, 218);

background-color: rgb(248, 248, 248);

}


/*垂直表头*/

QHeaderView::section::vertical {

padding: 5px;

border: none;

background-color: rgb(248, 248, 248);

alternate-background-color: rgb(255, 0, 0);

}


/*左上角按钮*/

QTableCornerButton::section {

padding: 0px;

border: none;

border-bottom: 1px solid rgb(214, 215, 218);

background-color: rgb(248, 248, 248);

}


5.QTableView属性设置

void setAttibutes(IN QTableView* pView,IN int nHeaderHeight,IN int nColumnHeight)
{
if ( pView == NULL )
{
QString strTemp = QStringLiteral("pView== NULL!设置表格属性失败!");
LOG_ALL_ERROR(strTemp);
QMessageBox::information(0,0,QStringLiteral("设置表格属性失败!"));
return;

}
}


pView->horizontalHeader()->setFixedHeight(nHeaderHeight); //设置表头的高度
pView->horizontalHeader()->setSectionsClickable(false); //设置表头不可点击(默认点击后进行排序)
//pView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);   //列宽都一致 
pView->horizontalHeader()->setStretchLastSection(true); //最后一列占满剩余空白
pView->setSelectionBehavior(QAbstractItemView::SelectRows); //设置选择行为时每次选择一行    
pView->setEditTriggers(QAbstractItemView::NoEditTriggers); //使表视图只读
pView->verticalHeader()->setDefaultSectionSize(nColumnHeight); //设置行高
//pView->setAlternatingRowColors(true); //可以交替颜色显示
pView->setShowGrid(false); //设置不显示格子线
pView->setCornerButtonEnabled(false); //左上角的按钮不可用,此按钮功能,一点击,全选


//水平滚动条
pView->horizontalScrollBar()->setStyleSheet("QScrollBar{background:transparent; height:10px;}"
"QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
"QScrollBar::handle:hover{background:gray;}"
"QScrollBar::sub-line{background:transparent;}"
"QScrollBar::add-line{background:transparent;}");


//垂直滚动条
pView->verticalScrollBar()->setStyleSheet("QScrollBar{background:transparent; width: 10px;}"
"QScrollBar::handle{background:lightgray; border:2px solid transparent; border-radius:5px;}"
"QScrollBar::handle:hover{background:gray;}"
"QScrollBar::sub-line{background:transparent;}"
"QScrollBar::add-line{background:transparent;}");
}





猜你喜欢

转载自blog.csdn.net/llfwdd/article/details/46602113
今日推荐