Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly clipped polygon labels item text #1228

Open
sergiud opened this issue Jan 11, 2023 · 1 comment
Open

Incorrectly clipped polygon labels item text #1228

sergiud opened this issue Jan 11, 2023 · 1 comment
Labels
bug issue

Comments

@sergiud
Copy link

sergiud commented Jan 11, 2023

Provide environment information

/usr/bin/python
Python 3.10.9
labelme 2b225b2

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 sergiud added the bug issue label Jan 11, 2023
@Roland-Pfeiffer
Copy link

Same problem here.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue
Projects
None yet
Development

No branches or pull requests

2 participants