PyQt5 – 标签的不同边角符号
在这篇文章中,我们将看到如何为不同的边角制作不同类型的曲线。我们可以使用setStyleSheet()方法为标签制作边框,但默认的边框是直角,即没有任何曲线,但我们也可以通过设置border-radius来制作曲线。这将使所有四个角都有相同的曲线。
下面是普通边框与不同角上的不同曲线的例子。
这可以通过setStyleSheet()来完成。
语法。
label.setStyleSheet("border :3px solid blue;"
"border-top-left-radius :35px;"
"border-top-right-radius : 20px; "
"border-bottom-left-radius : 50px; "
"border-bottom-right-radius : 10px")
Python
参数: 它接受字符串作为参数。
执行的动作: 改变每个角落的曲线。
代码。
# importing the required libraries
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
# set the title
self.setWindowTitle("Python")
# setting the geometry of window
self.setGeometry(60, 60, 600, 400)
# creating a label widget
self.label_1 = QLabel("Regular border", self)
# moving position
self.label_1.move(100, 100)
# setting up the border
self.label_1.setStyleSheet("border :3px solid blue;")
# resizing label
self.label_1.resize(100, 100)
# creating a label widget
self.label_2 = QLabel("Different curves", self)
# moving position
self.label_2.move(230, 200)
# setting curves at each corner
self.label_2.setStyleSheet("border :3px solid blue;"
"border-top-left-radius :35px;"
" border-top-right-radius : 20px; "
"border-bottom-left-radius : 50px; "
"border-bottom-right-radius : 10px")
# resizing the label
self.label_2.resize(100, 100)
# show all the widgets
self.show()
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
Python
输出: