labelme icon indicating copy to clipboard operation
labelme copied to clipboard

Incorrectly clipped polygon labels item text

Open sergiud opened this issue 1 year ago • 1 comments

Provide environment information

/usr/bin/python Python 3.10.9 labelme 2b225b2b384bdb25fb37678a9d28b8e545732473

What OS are you using?

ArchLinux

Describe the Bug

On my GNOME desktop, the item text of Polygon Labels entries is practically invisible:

Screenshot from 2023-01-12 00-28-04

The problem is caused by this code:

https://github.com/wkentaro/labelme/blob/2b225b2b384bdb25fb37678a9d28b8e545732473/labelme/widgets/label_list_widget.py#L46-L57

Since the delegate does not actually set any text, the reported text width is too narrow. textRect must account for the width of the text rendered by the QTextDocument instance.

The following patch fixes the problem:

diff --git a/labelme/widgets/label_list_widget.py b/labelme/widgets/label_list_widget.py
index 6164ef9..ace2b6e 100644
--- a/labelme/widgets/label_list_widget.py
+++ b/labelme/widgets/label_list_widget.py
@@ -4,6 +4,7 @@ from qtpy import QtGui
 from qtpy.QtGui import QPalette
 from qtpy import QtWidgets
 from qtpy.QtWidgets import QStyle
+import math
 
 
 # https://stackoverflow.com/a/2039745/4158863
@@ -44,6 +45,7 @@ class HTMLDelegate(QtWidgets.QStyledItemDelegate):
             )
 
         textRect = style.subElementRect(QStyle.SE_ItemViewItemText, options)
+        textRect.setWidth(int(math.ceil(self.doc.idealWidth())))
 
         if index.column() != 0:
             textRect.adjust(5, 0, 0, 0)

which sets the clip region correctly: Screenshot from 2023-01-12 00-40-15

Expected Behavior

Item text is visible.

To Reproduce

Run ArchLinux with GNOME desktop and packages installed using pacman.

sergiud avatar Jan 11 '23 23:01 sergiud

Same problem here.

/usr/bin/python3 Python 3.10.12 labelme 5.3.1 Kubuntu 22.04.03

Roland-Pfeiffer avatar Dec 28 '23 16:12 Roland-Pfeiffer