2款风格QPushButton

本文介绍了如何使用QSS对QPushButton进行美化,展示了两种不同风格的按钮界面效果,并提供了相应的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      代码:

复制代码
QPushButton {
    border: 1px solid #000000;
    border-radius: 5px;
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                   stop: 0 #dedede, stop: 0.5 #434343,
                                   stop: 0.51 #000000, stop: 1 #656a6d);
    color: #FFFFFF;
    font: bold 14px;
    min-width: 80px;
}

QPushButton:pressed {
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                   stop: 0 #cfcccc, stop: 0.5 #333232,
                                   stop: 0.51 #000000, stop: 1 #585c5f);
    color: #00CC00;
}
 
QPushButton:flat {
    border: none;
}
复制代码

      界面效果:

 

 2    代码:

复制代码
QPushButton {
    /* Let's make the size of the button 1,5 times of font size. */
    min-height: 1.5em;
    /* Font size just 1.*/
    font: 1em;
    /* Margins so that we get a little space on the left and right. */
    margin: 0 1px 0 1px;
    /* The font color */ 
    color: white;
    /* Here's the background gradient with start point, end point, 
       stop "percentage" and color, stop percentage and color. */
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #2198c0, stop: 1 #0d5ca6);
    /* We'll round the borders. */
    border-style: outset;
    /* Round radius will be 3px */
    border-radius: 3px;
    /* Border is only one pixel */
    border-width: 1px;
    /* Border color is now set */
    border-color: #0c457e;
}
 
/* This is style when button is pressed */
QPushButton:pressed {
    /* We'll just invert the gradient by changing the colors around. */
    background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                      stop: 0 #0d5ca6, stop: 1 #2198c0);
}
复制代码

    界面效果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值