■ QTabBar
#基本样式设置
QTabBar::tab{
font: 75 12pt "Arial"; #设置字体
width:84px; #设置宽度
height:30; #设置高度
margin-top:5px; #设置边距
margin-right:1px;
margin-left:1px;
margin-bottom:0px;
}
#最左边标签未选中时显示(因为需要左边打圆角,所以和其他背景图片不一样,注意字体颜色)
QTabBar::tab:first:!selected {
color:#000000;
border-image: url(:/common/images/common/左_normal.png);
}
#最左边标签被选中
QTabBar::tab:first:selected {
color:#FFFFFF;
border-image: url(:/common/images/common/左_pressed.png);
}
#最右边标签未选中时显示(因为需要右边打圆角,所以和其他背景图片不一样)
QTabBar::tab:last:!selected {
color:#000000;
border-image: url(:/common/images/common/右_normal.png);
}
#最右边标签被选中
QTabBar::tab:last:selected {
color:#FFFFFF;
border-image: url(:/common/images/common/右_pressed.png);
}
#中间的标签未被选择的显示
QTabBar::tab:!selected {
color:#000000;
border-image: url(:/common/images/common/中_normal.png);
}
#中间标签选中显示的图片
QTabBar::tab:selected {
color:#FFFFFF;
border-image: url(:/common/images/common/中_pressed.png);
}
tab标签居中显示
QTabWidget::tab-bar {
alignment: center;
}
5 鼠标停留tab标签的效果
鼠标放在标签上,可设置标签颜色或者背景图片
QTabBar::tab:hover{
background:rgb(255, 255, 255, 100);
}
6 去掉tabwidget的widget边框
QTabWidget::pane{
border:none;
}
QTabBar::tab{
background-color: rgb(255, 255, 255);
}
QTabBar::tab:hover{
background:rgb(46, 207, 38, 100);
}
QTabBar::tab:selected {
background:rgb(25, 34, 231, 100);
}
QTabWidget:pane{
border: 1px solid red;
top: -1px;
background-color:grey;
}
QTabBar::tab{
height:22px; background-color:grey; margin-right: 2px; margin-bottom:-2px;
}
QTabBar::tab:selected{
border:1px solid red;border-bottom-color: none;
}
QTabBar::tab:!selected{
border-bottom: 3px solid red;
}
■ QToolBar
void frmIconHelper::initWidget1()
{
QButtonGroup *btnGroup = new QButtonGroup(this);
btnGroup->addButton(ui->btn11);
btnGroup->addButton(ui->btn12);
btnGroup->addButton(ui->btn13);
btnGroup->addButton(ui->btn14);
initBtn(btnGroup, true);
ui->widget1->setProperty("flag", "left");
IconHelper::StyleColor styleColor;
styleColor.defaultBorder = true;
styleColor.position = "left";
styleColor.iconSize = 18;
styleColor.iconWidth = 30;
styleColor.iconHeight = 25;
styleColor.borderWidth = 4;
IconHelper::setStyle(ui->widget1, btnGroup->buttons(), icons, styleColor);
ui->btn11->click();
}
void frmIconHelper::initWidget2()
{
QButtonGroup *btnGroup = new QButtonGroup(this);
btnGroup->addButton(ui->btn21);
btnGroup->addButton(ui->btn22);
btnGroup->addButton(ui->btn23);
btnGroup->addButton(ui->btn24);
initBtn(btnGroup, true);
ui->widget2->setProperty("flag", "right");
IconHelper::StyleColor styleColor;
styleColor.defaultBorder = true;
styleColor.position = "right";
styleColor.iconSize = 18;
styleColor.iconWidth = 25;
styleColor.iconHeight = 20;
styleColor.borderWidth = 4;
styleColor.borderColor = "#32B9CF";
styleColor.setColor("#187294", "#B6D7E3", "#145C75", "#F0F0F0");
IconHelper::setStyle(ui->widget2, btnGroup->buttons(), icons, styleColor);
ui->btn22->click();
}
void frmIconHelper::initWidget3()
{
QButtonGroup *btnGroup = new QButtonGroup(this);
btnGroup->addButton(ui->btn31);
btnGroup->addButton(ui->btn32);
btnGroup->addButton(ui->btn33);
btnGroup->addButton(ui->btn34);
initBtn(btnGroup, false);
ui->widget3->setProperty("flag", "left");
IconHelper::StyleColor styleColor;
styleColor.position = "left";
styleColor.iconSize = 30;
styleColor.iconWidth = 40;
styleColor.iconHeight = 40;
styleColor.borderWidth = 3;
styleColor.borderColor = "#609EE9";
IconHelper::setStyle(ui->widget3, btnGroup->buttons(), icons, styleColor);
ui->btn33->click();
}
void frmIconHelper::initWidget4()
{
QButtonGroup *btnGroup = new QButtonGroup(this);
btnGroup->addButton(ui->btn41);
btnGroup->addButton(ui->btn42);
btnGroup->addButton(ui->btn43);
btnGroup->addButton(ui->btn44);
initBtn(btnGroup, false);
ui->widget4->setProperty("flag", "right");
IconHelper::StyleColor styleColor;
styleColor.position = "right";
styleColor.iconSize = 30;
styleColor.iconWidth = 40;
styleColor.iconHeight = 40;
styleColor.borderWidth = 3;
styleColor.borderColor = "#F7AE13";
styleColor.setColor("#FCDC97", "#54626F", "#FFF0BC", "#54626F");
IconHelper::setStyle(ui->widget4, btnGroup->buttons(), icons, styleColor);
ui->btn44->click();
}
void frmIconHelper::initWidget5()
{
QButtonGroup *btnGroup = new QButtonGroup(this);
btnGroup->addButton(ui->btn51);
btnGroup->addButton(ui->btn52);
btnGroup->addButton(ui->btn53);
btnGroup->addButton(ui->btn54);
initBtn(btnGroup, false);
ui->widget5->setProperty("flag", "top");
IconHelper::StyleColor styleColor;
styleColor.defaultBorder = true;
styleColor.position = "top";
styleColor.iconSize = 25;
styleColor.iconWidth = 25;
styleColor.iconHeight = 25;
styleColor.borderWidth = 3;
IconHelper::setStyle(ui->widget5, btnGroup->buttons(), icons, styleColor);
ui->btn51->click();
}
void frmIconHelper::initWidget6()
{
QButtonGroup *btnGroup = new QButtonGroup(this);
btnGroup->addButton(ui->btn61);
btnGroup->addButton(ui->btn62);
btnGroup->addButton(ui->btn63);
btnGroup->addButton(ui->btn64);
initBtn(btnGroup, false);
ui->widget6->setProperty("flag", "bottom");
IconHelper::StyleColor styleColor;
styleColor.defaultBorder = true;
styleColor.position = "bottom";
styleColor.iconSize = 25;
styleColor.iconWidth = 25;
styleColor.iconHeight = 25;
styleColor.borderWidth = 3;
styleColor.borderColor = "#A279C5";
styleColor.setColor("#292929", "#B6D7E3", "#10689A", "#F0F0F0");
IconHelper::setStyle(ui->widget6, btnGroup->buttons(), icons, styleColor);
ui->btn63->click();
}
void frmIconHelper::initBtn(QButtonGroup *btnGroup, bool textBesideIcon)
{
QList<QAbstractButton *> btns = btnGroup->buttons();
foreach (QAbstractButton *btn, btns) {
QToolButton *b = (QToolButton *)btn;
connect(b, SIGNAL(clicked(bool)), this, SLOT(btnClicked()));
b->setCheckable(true);
b->setToolButtonStyle(textBesideIcon ? Qt::ToolButtonTextBesideIcon : Qt::ToolButtonTextUnderIcon);
}
}
■ QScrollBar
verticalScrollBar = new QScrollBar(Qt::Vertical, this);
verticalScrollBar->setGeometry(770, 0, 30, 480);
label = new QLabel(this);
label->setText("这是一个测试");
label->setGeometry(300, 200, 100, 20);这里插入代码片
■