Designer中创建圆形按钮

Designer中创建圆形按钮

本文介绍了如何在Qt Designer中创建圆形按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on Python project using Qt Designer as the GUI creator. I tried to create a circular button, but there is only QPushButton, which is a square.I also tried to bind a click event to a circular image, but I do not know how to do that.

推荐答案

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

You should be able to get a round button by using a stylesheet.

在Qt Desgner中添加 QPushButton 并将其宽度和高度设置为40。然后右键单击该按钮,选择更改样式表...,然后粘贴以下样式表:

Add a QPushButton in Qt Desgner and set its width and height to 40. Then right-click the button, select "Change stylesheet...", and paste in the following 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
        );
    }

有关样式按钮的更多信息,请参见以及。

For more about styling buttons, see Customizing a QPushButton Using the Box Model and also the Qt Stylesheets Reference.

这篇关于如何在Qt Designer中创建圆形按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 21:58