Advertisement
Guest User

Untitled

a guest
May 30th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. import sys
  2. import os
  3.  
  4. # os.environ['QT_PREFERRED_BINDING'] = 'PyQt4'
  5. # os.environ['QT_PREFERRED_BINDING'] = 'PySide'
  6. # os.environ['QT_PREFERRED_BINDING'] = 'PyQt5'
  7. # os.environ['QT_PREFERRED_BINDING'] = 'PySide2'
  8.  
  9. from Qt import QtCore
  10. from Qt import QtWidgets
  11. from Qt import __binding__
  12. if __binding__.startswith('PyQt'):
  13. from Qt import uic
  14. elif __binding__.startswith('PySide'):
  15. from Qt import QtUiTools
  16.  
  17. print 'Using', __binding__
  18.  
  19.  
  20. class TestApp(QtWidgets.QMainWindow):
  21. """docstring for ClassName"""
  22. def __init__(self):
  23. super(TestApp, self).__init__()
  24.  
  25. if __binding__.startswith('PyQt'):
  26. # Main window
  27. self.ui = uic.loadUi('main_window.ui', self)
  28. # UI Module
  29. ui_module = uic.loadUi('module.ui')
  30. elif __binding__.startswith('PySide'):
  31. # Main window
  32. main_file = QtCore.QFile('main_window.ui')
  33. main_file.open(QtCore.QFile.ReadOnly)
  34. self.ui = QtUiTools.QUiLoader().load(main_file)
  35. # UI Module
  36. module_file = QtCore.QFile('module.ui')
  37. module_file.open(QtCore.QFile.ReadOnly)
  38. ui_module = QtUiTools.QUiLoader().load(module_file)
  39. module_file.close()
  40.  
  41. # Attach module to main window
  42. self.ui.verticalLayout.addWidget(ui_module)
  43.  
  44. # Edit widget
  45. self.ui.label = ui_module.label
  46. self.ui.label.setText('Hello')
  47.  
  48. self.ui.show()
  49.  
  50. if __name__ == "__main__":
  51. app = QtWidgets.QApplication(sys.argv)
  52. win = TestApp()
  53. sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement