PyQt5 – 在复选框中设置不同弧度的指示器角落

PyQt5 – 在复选框中设置不同弧度的指示器角落

在这篇文章中,我们将看到如何在复选框中的指示器的不同角落设置不同的曲线,尽管在改变半径的帮助下,我们可以使方形指示器变成圆形指示器。

下面是普通指示器与不同曲线指示器的表示。

PyQt5 - 在复选框中设置不同弧度的指示器角落

为了做到这一点,我们必须改变指标的样式表代码,并添加不同的曲线。

QCheckBox::indicator
{
border : 2px solid black; 
width : 20px;
height : 20px;
border-top-left-radius :10px;
border-top-right-radius : 1px; 
border-bottom-left-radius : 1px; 
border-bottom-right-radius : 11px
}

以下是执行情况

# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
  
class Window(QMainWindow):
  
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
    # method for widgets
    def UiComponents(self):
        # creating the check-box
        checkbox = QCheckBox('Geek ?', self)
  
        # setting tristate check box
        checkbox.setTristate(True)
  
        # setting geometry of check box
        checkbox.setGeometry(200, 150, 100, 40)
  
        # adding border to the check box and padding
        # adding border to indicator and setting size
        # setting border radius for different corner
        checkbox.setStyleSheet("QCheckBox"
                               "{"
                               "border : 2px solid black;"
                               "padding : 10px;"
                               "}"
                               "QCheckBox::indicator"
                               "{"
                               "border : 2px solid black;"
                               "width : 20px;"
                               "height : 20px;"
                               "border-top-left-radius :10px;"
                               "border-top-right-radius : 1px; "
                               "border-bottom-left-radius : 1px; "
                               "border-bottom-right-radius : 11px"
                               "}")
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :

PyQt5 - 在复选框中设置不同弧度的指示器角落

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程