您可以使用QSS(Qt样式表)来设置按钮的背景以图标的形式存在。以下是一个示例:

QPushButton {
    background-color: transparent;  // 设置按钮的背景色为透明
    border: none;  // 移除按钮的边框
    background-image: url(:/path/to/icon.png);  // 设置按钮的背景图片
    background-repeat: no-repeat;  // 设置背景图片不重复
    background-position: center;  // 设置背景图片居中
    min-width: 48px;  // 设置按钮的最小宽度
    min-height: 48px;  // 设置按钮的最小高度
}

您需要将:path/to/icon.png替换为实际的图标路径。然后,将该QSS样式表应用于按钮:

QPushButton *button = new QPushButton("按钮");
button->setStyleSheet("QPushButton { background-color: transparent; border: none; background-image: url(:/path/to/icon.png); background-repeat: no-repeat; background-position: center; min-width: 48px; min-height: 48px; }");

请确保将:path/to/icon.png替换为实际的图标路径。这样,按钮的背景将以图标的形式存在

qt怎么让按钮的背景已图标的形式存在

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

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