Guest User

Untitled

a guest
Apr 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <QApplication>
  2. #include <QWidget>
  3. #include <QVBoxLayout>
  4. #include <QPushButton>
  5. #include <QMainWindow>
  6. #pragma push_macro("slots")
  7. #undef slots
  8. #include "Python.h"
  9. #pragma pop_macro("slots")
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13. PyObject *pName, *pModule, *pDict, *pFunc;
  14.  
  15.  
  16. // Initialize QApplication and setup basic widgets.
  17. QApplication app (argc, argv);
  18. QMainWindow mainWindow (nullptr);
  19. QPushButton button ("test", &mainWindow);
  20. QWidget * widget = new QWidget(&mainWindow);
  21. mainWindow.setCentralWidget(widget);
  22. auto l = new QVBoxLayout ();
  23. widget->setLayout(l);
  24. l->addWidget(&button);
  25.  
  26. // Initialize the Python Interpreter
  27. Py_Initialize();
  28.  
  29.  
  30. // Build the name object
  31. pName = PyUnicode_FromString("runPyQt");
  32.  
  33. // Load the module object
  34. pModule = PyImport_Import(pName);
  35.  
  36. if (!pModule){
  37. Py_Finalize();
  38. return 1;
  39. }
  40.  
  41. pDict = PyModule_GetDict(pModule);
  42.  
  43. pFunc = PyDict_GetItemString(pDict, "main");
  44.  
  45. if (PyCallable_Check(pFunc))
  46. {
  47. PyObject_CallObject(pFunc, nullptr);
  48. } else
  49. {
  50. PyErr_Print();
  51. }
  52.  
  53. mainWindow.show();
  54.  
  55. int r = 0;
  56.  
  57. r = QApplication::exec();
  58.  
  59. // Clean up
  60. Py_DECREF(pModule);
  61. Py_DECREF(pName);
  62.  
  63. // Finish the Python Interpreter
  64. Py_Finalize();
  65.  
  66. return r;
  67. }
  68.  
  69. import sys
  70. if sys.platform.startswith( 'linux' ) :
  71. from OpenGL import GL
  72.  
  73. from PyQt5.QtWidgets import QApplication, QPushButton, QMainWindow
  74.  
  75.  
  76.  
  77. def main():
  78. app = QApplication.instance()
  79. widgets = app.topLevelWidgets()
  80. for widget in widgets:
  81. if type(widget) is QMainWindow:
  82. break
  83. widget = widget.centralWidget()
  84.  
  85. widget.layout().addWidget(QPushButton('Hello from PyQt'))
Add Comment
Please, Sign In to add comment