Need some help migrating code from PySide2 to PySide6 (SideFX decided to update)
-
Hello all,
SideFX has decided to update Houdini to PySide6 from PySide2 and, predictably, it has broken some of the front end code that the tools my company builds. For reference, I am not a Qt expert by any means, but I am well versed in basically everything else Python. I am also not the original author of this code, but I need to figure out how to create the same effect in PySide6. The root of the issue is that QApplication.desktop() has been removed. Here is the (currently) offending code:
def center(base_instance): """ Center the GUI in the screen, so that it doesn't show up in the top left or off-screen when the window is launched. """ geo = base_instance.geometry() screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos()) centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center() geo.moveCenter(centerPoint) base_instance.setGeometry(geo)
I have looked at QtGui.QScreen as the Qt Changes page says is supposed to be the replacement, but I cannot find any of the functionality that is used here. There is nothing for checking the cursor position. I do not see where to select which screen is the target. I am seeing that once I get there I can change the centerPoint = line to use QScreen.AvailableGeometry.center(), but the screen selection bit is being arcane right now.
I am hoping that I don't run into too many more errors like this, but I think that getting the answer here might help me clear up future errors.
-
Hi and welcome to devnet,
I think you are looking for QGuiApplication.screenAt. QApplication is a subclass so you can directly use it with it.
-
Hi and welcome to devnet,
I think you are looking for QGuiApplication.screenAt. QApplication is a subclass so you can directly use it with it.
@SGaist said in Need some help migrating code from PySide2 to PySide6 (SideFX decided to update):
Hi and welcome to devnet,
I think you are looking for QGuiApplication.screenAt. QApplication is a subclass so you can directly use it with it.
Thanks for the advice, I will go give it a look to see what I can do with this. Thanks for the suggestion.
-
@SGaist that got me there, thank you.
-
Excellent !
Then please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem correct so other forum users may know a solution has been found :-)
-