9797LABEL_OPACITY = 128
9898
9999
100+ def _measure_text_width (font_metrics , text ):
101+ if hasattr (font_metrics , "horizontalAdvance" ):
102+ return font_metrics .horizontalAdvance (text )
103+ return font_metrics .width (text )
104+
105+
100106class LabelingWidget (LabelDialog ):
101107 """The main widget for labeling images"""
102108
@@ -3720,12 +3726,12 @@ def update_attributes(self, shape_index):
37203726 if hasattr (self , "grid_layout_container" ):
37213727 font_metrics = QFontMetrics (self .grid_layout_container .font ())
37223728 else :
3723- font_metrics = QLabel ().font ()
3729+ font_metrics = QFontMetrics ( QLabel ().font () )
37243730 available_width = self .scroll_area .width () - 30
37253731 property_display = property
3726- if font_metrics . width ( property ) > available_width :
3732+ if _measure_text_width ( font_metrics , property ) > available_width :
37273733 while (
3728- font_metrics . width ( property_display + "..." )
3734+ _measure_text_width ( font_metrics , property_display + "..." )
37293735 > available_width
37303736 and len (property_display ) > 1
37313737 ):
@@ -3747,18 +3753,19 @@ def update_attributes(self, shape_index):
37473753 main_layout .setSpacing (2 )
37483754
37493755 def get_truncated_text (text , max_width ):
3750- if font_metrics . width ( text ) <= max_width :
3756+ if _measure_text_width ( font_metrics , text ) <= max_width :
37513757 return text , text
37523758 truncated = text
37533759 while (
3754- font_metrics .width (truncated + "..." ) > max_width
3760+ _measure_text_width (font_metrics , truncated + "..." )
3761+ > max_width
37553762 and len (truncated ) > 1
37563763 ):
37573764 truncated = truncated [:- 1 ]
37583765 return truncated + "..." , text
37593766
37603767 def get_button_width (text ):
3761- return font_metrics . width ( text ) + 30
3768+ return _measure_text_width ( font_metrics , text ) + 30
37623769
37633770 def create_radio_button_with_handler (
37643771 display_text , original_text , prop , shape_idx
0 commit comments