11from PyQt6 import QtCore , QtGui , QtWidgets
22import typing
33
4+
45class BlocksCustomFrame (QtWidgets .QFrame ):
56 def __init__ (self , parent = None ):
67 super ().__init__ (parent )
78
89 self ._radius = 10
9- self ._left_line_width = 15
10- self ._is_centered = False
11- self .text = ""
10+ self ._left_line_width = 15
11+ self ._is_centered = False
12+ self .text = ""
1213
1314 self .setMinimumHeight (40 )
1415 self .setMinimumWidth (300 )
@@ -28,7 +29,7 @@ def setCentered(self, centered: bool):
2829 self ._is_centered = centered
2930 self .update ()
3031
31- def setProperty (self , name : str | None , value : typing .Any ) -> bool :
32+ def setProperty (self , name : str | None , value : typing .Any ) -> bool :
3233 if name == "text" :
3334 self .text = value
3435 self .update ()
@@ -39,7 +40,6 @@ def paintEvent(self, a0):
3940 painter = QtGui .QPainter (self )
4041 painter .setRenderHint (QtGui .QPainter .RenderHint .Antialiasing )
4142
42-
4343 rect = QtCore .QRectF (self .rect ())
4444 pen = QtGui .QPen (QtGui .QColor (20 , 20 , 20 , 70 ))
4545 pen .setWidth (2 )
@@ -48,58 +48,47 @@ def paintEvent(self, a0):
4848 painter .drawRoundedRect (rect .adjusted (1 , 1 , - 1 , - 1 ), self ._radius , self ._radius )
4949
5050 if self .text :
51-
5251 painter .setPen (QtGui .QColor ("white" ))
5352 font = QtGui .QFont ()
5453 font .setPointSize (12 )
5554 painter .setFont (font )
5655 fm = painter .fontMetrics ()
5756 text_width = fm .horizontalAdvance (self .text )
58- baseline = fm .ascent ()
57+ baseline = fm .ascent ()
5958
6059 margin = 10
6160 spacing = 8
6261 line_center_y = margin + baseline // 2
6362
6463 if self ._is_centered :
65- left_line_width = self ._left_line_width
64+ left_line_width = self ._left_line_width
6665 right_line_width = self ._left_line_width
67-
66+
6867 total_content_width = (
6968 left_line_width + spacing + text_width + spacing + right_line_width
7069 )
7170
7271 start_x = (self .width () - total_content_width ) // 2
73- x = max (margin , start_x )
72+ x = max (margin , start_x )
7473
7574 else :
76- left_line_width = self ._left_line_width
75+ left_line_width = self ._left_line_width
7776 x = margin
78- right_line_width = 0
79-
80- small_rect = QtCore .QRect (
81- x ,
82- line_center_y - 1 ,
83- left_line_width ,
84- 3
85- )
77+ right_line_width = 0
78+
79+ small_rect = QtCore .QRect (x , line_center_y - 1 , left_line_width , 3 )
8680 painter .fillRect (small_rect , QtGui .QColor ("white" ))
8781 x += left_line_width + spacing
8882
8983 painter .drawText (x , margin + baseline , self .text )
9084 x += text_width + spacing
9185
9286 if self ._is_centered :
93- big_rect_width = right_line_width
87+ big_rect_width = right_line_width
9488 else :
9589 remaining_width = self .width () - x - margin
96- big_rect_width = max (0 , remaining_width )
90+ big_rect_width = max (0 , remaining_width )
9791
98- big_rect = QtCore .QRect (
99- x ,
100- line_center_y - 1 ,
101- big_rect_width ,
102- 3
103- )
92+ big_rect = QtCore .QRect (x , line_center_y - 1 , big_rect_width , 3 )
10493
105- painter .fillRect (big_rect , QtGui .QColor ("white" ))
94+ painter .fillRect (big_rect , QtGui .QColor ("white" ))
0 commit comments