Qt 5.8 + python3
-
Hi, all i'm trying to develop an application in c++ with the ability to scripting it through an add-on mechanism using python as language.
The idea is to have the main interface, the textedtior, and the main interface component in c++
the through python, users can interact with the editor, manipulating text trough QTextCursor, adding widgets and so on. Is this is possible? Is possible to create a widget in python and parenting it to an existing widget created with c++?? if so which is the correct Qt bind to achieve this??I've look at pythonqt, but it seems no longer supported(at last it doesn't support >Qt5.6)
Instead I'dont understand if PyQt5 is only a bind without any c++ hybrid application same for PySide. I would like also use pybind11 for my class binds along with qt binds is this possible??
Unfortunately on google i found only pure python qt usage and no c++/python hybrid.
Thanks! and sorry for lot questions
-
Hi,
Something's not completely clear. You would like to be able to run complex python scripts possibly with modules like PyQt through your application and get them to talk together, is that correct ?
-
Yes, basically something like Sublime or Atom does: text manipulation, completition and TextEditor stuff like this plus the abilty to add widgets through python.
In python i import the qt modules, the application modules(maybe created with pybind11) and use the provided api to access the application object instance and manipulate them. -
Trying this runs into an error for me(python3.6 + Qt5.8 )
#include "mainwindow.h" #include "ui_mainwindow.h" #include <python3.6m/Python.h> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); }
leads to
/usr/include/python3.6m/object.h:448: error: expected unqualified-id before ‘;’ token PyType_Slot *slots; /* terminated by slot==0. */ ^
-
@SGaist
Exactly, both extending, by providing my own api to python an embedding in order to execute the script when necessary on even at start up for gui.an example of usage could be like this:
from myApp import Commands, ActionManager, TextEditor # is this necessary? from pyQt5 import ......... # DuplicateLineUp inherit from commands so when python execute the script # this command is registered internally in c++(i suppose) # when the user call for exampl Ctrl +D, exec is called class DuplicateLineUp(Commands): def exec(): textEditor = TextEditor.activeTexteditor() # now cursor is a Qt Object so I need PyQt or PySide?? cursor.moveToBeginOfLine() # and so on
another example that involve widgets
from myApp import Workspace # again pyQt5 or pyside2??? from pyQt5 import QTextEditor class MarkDownPreviewer(QTextEditor): # subclass QTextEditor # register the interface # call c++ api to split the central widget panel = Workspace.splitPanel(direction='right') # call c++ api to parenting the python created widget to # the c++ SplitView panel.setWidget(MarkDownPreviewer)
That's basically what i want to achieve. Currently I' don't know how.. I need to study further, but i need a direction and also the library that should do the work(and that's my question: since pythonQt seems the right choice, but ' it's not updated, does pyQt5 or pyside 2 work in an embedded/extended environment?? and if so how to get started?? I need i hybrd c++/python + Qt tutorial and not pure python app)
-
@the_ You'll likely need to use
CONFIG += no_keywords
. Take a look at Using Qt with 3rd Party Signals and Slots.PySide and PyQt are just bindings to write Qt application directly in python. So indeed PythonQt looks exactly what you want to have.
From the looks of the svn repository, the project is still active, the current last commit is from February 2017
-
@SGaist unfortunately i've downloaded the source and tried to compile it but it gives me error about missing enumerator, if i don't get wrong is 'WindowCancelButtonHint', that in fact is missing from the last Qt version.. I'll post an issue on github on pythonQt and see.. So at the end it was the first thing i've thought.
Edit: it seems that github version is outdated, and from commits on sourceforge instead seems they fixed the missing enum
-
I've took a look at the official project on SourceForge so we may have something different currently.