【Qt-Bar】

发布时间:2023年12月25日

■ 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);这里插入代码片


文章来源:https://blog.csdn.net/sinat_23896491/article/details/135205985
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。