可以使用QSS中的background-image属性为QPushButton插入icon,并使用padding属性将icon放在文字的左边。

以下是一个示例的QSS代码:

QPushButton { padding-left: 20px; padding-right: 10px; padding-top: 5px; padding-bottom: 5px; border: none; background-color: transparent; background-image: url(:/path/to/your/icon.png); background-position: left center; background-repeat: no-repeat; background-origin: content; background-clip: padding; text-align: left; }

将":/path/to/your/icon.png"替换为你自己的icon的文件路径。

用qss给qpushbutton插入icon并将icon放在文字的左边

原文地址: https://www.cveoy.top/t/topic/i7Nr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录