如何在QT左侧的QPushButton上设置图像?


How to Set Image on QPushButton on Left hand side in QT?

如何在QT左侧的QPushButton上设置图像?

我正在使用以下代码使用样式表在按钮上设置图像。
但这给了我相同的图像很多次,我只希望在按钮的左侧也进行一次显示。enter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 b1->setStyleSheet(

              "background-image: url(:/user.gif);"
              "border-style: outset;"
              "border-width: 2px;"
              "border-radius: 10px;"
              "border-color: black;"
              "font: bold 16px;"
              "color: black;"
              "min-width: 10em;"
              "min-height: 0.75em;"
              "margin: 0 1px 0 1px;"
              "color:rgb(0,0,0);"
              "padding: 6px;"
               );

我使用:

解决了我的问题

1
2
"background-repeat:no-repeat;"                  
              "background-position:left top;"


您需要在样式表中添加background-repeat no-repeat;