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

Additions needed for PySide6/PyQt6 support (QFontMetricsF.width, QLineEdit.getTextMargins and QtWidgets.QUndoCommand) #365

Closed
random-developer opened this issue Sep 1, 2022 · 3 comments · Fixed by #366

Comments

@random-developer
Copy link
Contributor

I recently ported pycode to support PySide6, including removing the pyqode.qt compatibility module and using qtpy instead. To complete that, I needed to add some additional support:

import os
from qtpy import PYSIDE6_API
qt_api = os.environ['QT_API'].lower()
if qt_api in PYSIDE6_API:
    from PySide6.QtGui import *
    from PySide6.QtWidgets import *
    QFontMetrics.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs)
    QFontMetricsF.width = lambda self, *args, **kwargs: self.horizontalAdvance(*args, **kwargs)
    QLineEdit.getTextMargins = lambda self: (self.textMargins().left(), self.textMargins().top(), self.textMargins().right(), self.textMargins().bottom())

Additionally I needed to add in a single source file (I didn't modify my qtpy files at all):

try:
    from qtpy import QtGui
    QtWidgets.QUndoCommand = QtGui.QUndoCommand
except:
    pass
@dalthviz
Copy link
Member

dalthviz commented Sep 1, 2022

Hi @random-developer thank you for the feedback! Regading the logic/changes to add:

Checking the linked files you can see that there are alredy some of the changes you need implemented (like for the QFontMetricsF.width method aliasing). Most probably these changes should also be added to the logic to handle PyQt6.

Also, do you know if this alising is needed starting from and specific version of PySide6?

If you want to helps us with these additions let us know!

@dalthviz dalthviz added this to the v2.2.1 milestone Sep 1, 2022
@dalthviz dalthviz changed the title Additions needed for PySide6 support Additions needed for PySide6 support (QFontMetricsF.width, QLineEdit.getTextMargins and QtWidgets.QUndoCommand) Sep 1, 2022
@random-developer
Copy link
Contributor Author

random-developer commented Sep 2, 2022

Hi @dalthviz, I don't know if there's a specific version of PySide6 where this becomes necessary. (I happen to be using 6.3.1 and have only previously used PyQt5.)

I've never created a GitHub PR before but I'll give it a shot with these changes! To do that, do I need to clone the repo to my own account first, submit there, then request a merge? (Something else I've never done on GitHub), or do I just clone the repo here locally, commit my changes locally (in a new branch?) and then push them?

@dalthviz
Copy link
Member

dalthviz commented Sep 2, 2022

Thanks @random-developer ! Regarding how to contribute, you can check our contributing guide at https://github.com/spyder-ide/qtpy/blob/master/CONTRIBUTING.md (basically you need to create a fork from this repo into your account and then work from a branch on your fork which you then will use to submit a PR using the GitHub interface)

Also, if this changes help with the latest PySide6 (6.3.1) then I would say that is good to have them 👍

If you need any further guidance let us know!

@dalthviz dalthviz changed the title Additions needed for PySide6 support (QFontMetricsF.width, QLineEdit.getTextMargins and QtWidgets.QUndoCommand) Additions needed for PySide6/PyQt6 support (QFontMetricsF.width, QLineEdit.getTextMargins and QtWidgets.QUndoCommand) Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants