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

Make sure the text is not croped #2850

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

seb5g
Copy link

@seb5g seb5g commented Oct 18, 2023

Detail the reasoning behind the code change. If there is an associated issue that this PR will resolve add

Fixes #2849

I just added a fixed number (6) to the MaximumWidth or Height of the VerticalLabel with respect to the label size hint.

Other Tasks

Bump Dependency Versions

Files that need updates

Confirm the following files have been either updated or there has been a determination that no update is needed.

  • [ X] README.md
  • [ X] setup.py
  • [ X] tox.ini
  • [X ] .github/workflows/main.yml and associated requirements.txt and conda environemt.yml files
  • [ X] pyproject.toml
  • [ X] binder/requirements.txt
Pre-Release Checklist

Pre Release Checklist

  • Update version info in __init__.py
  • Update CHANGELOG primarily using contents from automated changelog generation in GitHub release page
  • Have git tag in the format of pyqtgraph-
Post-Release Checklist

Steps To Complete

  • Append .dev0 to __version__ in __init__.py
  • Announce on mail list
  • Announce on Twitter

@j9ac9k
Copy link
Member

j9ac9k commented Oct 29, 2023

I agree that this is an issue, but I'm not sure this is the fix we want... I generally try and avoid hard-coding pixels to oversize fields and instead try and set the margins correctly.

As we can see, the height/width is set based on the self.hint attribute, which is set here:

https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/widgets/VerticalLabel.py#L52

...but looking at the Qt documentation, I'm really confused, QPainter::drawText should return None... but it is returning a QRect? ... I'll investigate a bit more.

@seb5g
Copy link
Author

seb5g commented Dec 19, 2023

I agree with your comment but somehow something seems to be wrong on the qt side. I think the sizehint is often wrong as many times the labels within a widget are not properly visible.

As for the QPainter::drawTest thing, it is because of pyqt mechanism:

You see that the overloaded method:

void QPainter::drawText(const QRectF &rectangle, int flags, const QString &text, QRectF *boundingRect = nullptr)

take as third argument a pointer to a QRectF. In the usual pyqt5/6 wrapper this translates into a returned value being this QRectF. This is why the hint has been set as the returned value.

Did you see another possible fix?

@seb5g
Copy link
Author

seb5g commented Dec 19, 2023

running this minimal example reproduce the result:

if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)

    label = VerticalLabel('mysuperlabel', orientation='hor')
    label.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop | QtCore.Qt.AlignmentFlag.AlignHCenter)
    f = label.font()
    f.setPixelSize(25)
    label.setFont(f)
    label.show()
    sys.exit(app.exec())

which shows the croping
image

while this is working fine:

    import sys
    app = QtWidgets.QApplication(sys.argv)

    label = QtWidgets.QLabel('mysuperlabel')
    label.setAlignment(QtCore.Qt.AlignmentFlag.AlignTop | QtCore.Qt.AlignmentFlag.AlignHCenter)
    f = label.font()
    f.setPixelSize(25)
    label.setFont(f)
    label.show()
    sys.exit(app.exec())

image

@seb5g
Copy link
Author

seb5g commented Dec 19, 2023

Allright I found out the bug,
in fact the sizeHint method is never called during the label creation, therefore the size cannot be set to the boundingrect as discussed above. Just adding a statement with the resize method having the sizeHint returned value as argument solves our issue.
I'll push some code in that direction

@seb5g
Copy link
Author

seb5g commented Dec 19, 2023

well it seems however that the styling in the DockLabel is messing up things also, there is a border width (bottom) in there that is hard coded to 2pxl and this is also explaining why the bottom of the writing are wrong. Using the darkstyling adds an even bigger border (by default) so things get worse...
However I could not figure how to properly solve this...except adding some extra space as I did previously (because this border styling cannot be taken into consideration by the bouding rect of the painter drawtext method)... Could you have a look in those directions?

@seb5g
Copy link
Author

seb5g commented Jan 13, 2024

@j9ac9k could you have a look at what I dug out?

@@ -60,14 +60,17 @@
self.setMinimumHeight(self.hint.width())
else:
self.setMinimumHeight(0)
size = QtCore.QSize(self.hint.height(), size.height())

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable size is not used.
self.setMinimumHeight(0)
self.setMaximumWidth(16777215)
if self.forceWidth:
self.setMinimumWidth(self.hint.width())
else:
self.setMinimumWidth(0)
size = QtCore.QSize(size.width(), self.hint.height()+5)

Check notice

Code scanning / CodeQL

Unused local variable Note

Variable size is not used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DockLabel are croped
2 participants