您当前的位置: 首页 >  qt

令狐掌门

暂无认证

  • 0浏览

    0关注

    513博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Qt按钮左边图片右边文字

令狐掌门 发布时间:2021-04-27 20:51:45 ,浏览量:0

在Qt中实现按钮的图片在左,文字在右,主要有两种方法,如下:

方法一 : 设置按钮内部布局
ui->pushButton->setIcon(QIcon(":/pic/share.png"));
ui->pushButton->setLayoutDirection(Qt::LeftToRight);

效果如下: 在这里插入图片描述 按钮的其它效果可以再用样式表实现。

方法二 :样式表
QString btnStyle = "QPushButton{"
    "background-image: url(:/pic/share.png);"
    "background-repeat: no-repeat;"
    "background-origin: padding;"
    "background-position: left;"
    "padding-left:30px;"
    "border: none;"
    "background-color: rgb(255, 255, 255);"
    "color:rgb(0, 0, 0);"
    "text-align:left;"
"}";

ui->pushButton->setStyleSheet(btnStyle);
关注
打赏
1652240117
查看更多评论
立即登录/注册

微信扫码登录

0.0376s