kiryha Posted September 26, 2018 Share Posted September 26, 2018 Hello! I have my UI window done in QT Designer (with PySide) and I launch this window with a code in PyCharm successfully: from PySide.QtGui import * from UI import createScene_Main class CreateScene(QWidget, createScene_Main.Ui_CreateScene): def __init__(self): super(CreateScene, self).__init__() # SETUP UI self.setupUi(self) app = QApplication([]) CS = CreateScene() CS.show() app.exec_() When I try to import this code in Houdini (changing PySide to PySide2 in this code and in UI file as well) I get an error: NameError: name 'QWidget' is not defined. How can I fix it? Quote Link to comment Share on other sites More sharing options...
toadstorm Posted September 26, 2018 Share Posted September 26, 2018 PySide2 / Qt5 has migrated many of their classes away from the QtGui module to QtWidgets. QWidget is one of them. I don't like the "from module import *" way of doing things in general because it makes things like this harder to track later on, but in your example you could add the line: from PySide2.QtWidgets import * 1 Quote Link to comment Share on other sites More sharing options...
kiryha Posted September 26, 2018 Author Share Posted September 26, 2018 Thanks, Henry, that works, but then I get a new error in my UI file: self.verticalLayout = QtGui.QVBoxLayout(CreateScene) AttributeError: 'module' object has no attribute 'QVBoxLayout' The PySyde2 import in UI file done like: from PySide2 import QtCore, QtGui I used QT designer shipped with PySide to build UI. It will be a problem if I will run those UIs with PySide2, right? I just can't pip install PySide2 to my PC, getting an error (Could not find a version that satisfies the requirement PySide2 (from versions: ) No matching distribution found for PySide2) 51 minutes ago, toadstorm said: I don't like the "from module import *" way How should I import PySide modules in a better way? Quote Link to comment Share on other sites More sharing options...
toadstorm Posted September 26, 2018 Share Posted September 26, 2018 QVBoxLayout is also part of QtWidgets now, not QtGui, so you'd have to modify your import accordingly. Everyone has different opinions on the import style, but I typically use something like: from PySide2 import QtGui, QtWidgets, QtCore That way when you're calling these functions later on, it's very clear which module you're using: self.verticalLayout = QtWidgets.QVBoxLayout(parent) For cross-compatibility between PySide and PySide2, I'd recommend checking out Qt.py. It allows you to write all of your code as if it were PySide2, but will translate to PyQt4, PySide, PyQt5, and PySide2 interchangeably. There's a few gotchas when dealing with models and .data() overloads, but it's mostly seamless. I'd recommend avoiding Qt Designer in general as it has some limitations that may cause more harm than good later on. If you need it, though, you can use Qt.py's QtCompat module for the loadUi() function. 1 Quote Link to comment Share on other sites More sharing options...
kiryha Posted September 27, 2018 Author Share Posted September 27, 2018 (edited) I don`t need a cross-compatibility between PySide and PySide2. Just building tools which will work in Houdini 16.5 and later, trying to keep things simple as possible for reliability. If I understand correctly, PySide2 requires Python 3.5, but it is Python27 in 16.5, so how it works then? I guess it worth to explain why I had an initial question at least now. I have some experience building UI with PySide for Maya and Nuke and I was thinking it would be the same process to build a UI for Houdini but it is not. Edited September 27, 2018 by kiryha Quote Link to comment Share on other sites More sharing options...
kiryha Posted September 27, 2018 Author Share Posted September 27, 2018 I found a working solution (using a designer, which is fine for me right now): import hou import os from PySide2 import QtCore, QtUiTools, QtWidgets class CreateScene(QtWidgets.QWidget): def __init__(self): super(CreateScene,self).__init__() ui_file = "pathTo/createScene.ui" self.ui = QtUiTools.QUiLoader().load(ui_file, parentWidget=self) self.setParent(hou.ui.mainQtWindow(), QtCore.Qt.Window) def run(): CS = CreateScene() CS.show() Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted September 28, 2018 Share Posted September 28, 2018 On 9/27/2018 at 6:28 AM, kiryha said: PySide2 requires Python 3.5, but it is Python27 in 16.5, so how it works then? This is not true. PySide2 (currently officially maintained my Qt company) is built for Py2 and Py3. Quote I have some experience building UI with PySide for Maya and Nuke and I was thinking it would be the same process to build a UI for Houdini but it is not. The difference is in Qt4/Qt5, not in Maya/Houdini. Quote Link to comment Share on other sites More sharing options...
kiryha Posted September 28, 2018 Author Share Posted September 28, 2018 Somebody on tech artist forum told that PySide2 is supported by Python 3 only when I was not able to install it on my computer (but I notice that according to a docs it's not the case). I am still not able to do it. Quote Link to comment Share on other sites More sharing options...
Stalkerx777 Posted September 28, 2018 Share Posted September 28, 2018 It's true that official release does not provide Python2.7 binaries for windows: https://download.qt.io/official_releases/QtForPython/pyside2/ Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.