gpt4 book ai didi

python - 如何在 Qt Designer 中创建圆形按钮

转载 作者:行者123 更新时间:2023-12-05 00:41:40 25 4
gpt4 key购买 nike

我正在使用 Qt Designer 作为 GUI 创建者来开发 Python 项目。我试图创建一个圆形按钮,但只有 QPushButton,它是一个正方形。我也尝试将点击事件绑定(bind)到圆形图像,但我不知道该怎么做。

最佳答案

您应该能够通过使用样式表来获得圆形按钮。

在Qt Desgner中添加一个QPushButton并将其宽高设置为40。然后右键单击该按钮,选择“Change stylesheet...”,并粘贴如下样式表:

QPushButton {
color: #333;
border: 2px solid #555;
border-radius: 20px;
border-style: outset;
background: qradialgradient(
cx: 0.3, cy: -0.4, fx: 0.3, fy: -0.4,
radius: 1.35, stop: 0 #fff, stop: 1 #888
);
padding: 5px;
}

QPushButton:hover {
background: qradialgradient(
cx: 0.3, cy: -0.4, fx: 0.3, fy: -0.4,
radius: 1.35, stop: 0 #fff, stop: 1 #bbb
);
}

QPushButton:pressed {
border-style: inset;
background: qradialgradient(
cx: 0.4, cy: -0.1, fx: 0.4, fy: -0.1,
radius: 1.35, stop: 0 #fff, stop: 1 #ddd
);
}

有关样式按钮的更多信息,请参阅 Customizing a QPushButton Using the Box Model还有Qt Stylesheets Reference .

关于python - 如何在 Qt Designer 中创建圆形按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22469885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com