Is it possible to embed C++ widget to PyQt application?
I have a PyQt5 application and most widgets written in Python. I want to write some widget in C++ Qt to make it faster and then embed it into my PyQt QMainWindow.
Is it possible?
python c++ pyqt pyqt5
add a comment |
I have a PyQt5 application and most widgets written in Python. I want to write some widget in C++ Qt to make it faster and then embed it into my PyQt QMainWindow.
Is it possible?
python c++ pyqt pyqt5
add a comment |
I have a PyQt5 application and most widgets written in Python. I want to write some widget in C++ Qt to make it faster and then embed it into my PyQt QMainWindow.
Is it possible?
python c++ pyqt pyqt5
I have a PyQt5 application and most widgets written in Python. I want to write some widget in C++ Qt to make it faster and then embed it into my PyQt QMainWindow.
Is it possible?
python c++ pyqt pyqt5
python c++ pyqt pyqt5
edited Nov 23 '18 at 4:26
eyllanesc
74.4k103156
74.4k103156
asked May 30 '17 at 9:45
Felix
84141433
84141433
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use SIP to be able to execute a widget created in C ++ from python, in the following link I show an example of how to do it.
The structure of the example is as follows:
├── configure.py
├── sip
│ ├── AnalogClock.sip
│ └── PyAnalogClock.sip
└── src
├── analogclock.cpp
├── analogclock.h
├── analogclockl_global.h
└── AnalogClock.pro
In the src folder you must create the widget library
In the sip folder you must place the structure of the class that you will expose:
AnalogClock.sip
%Import QtGui/QtGuimod.sip
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
class AnalogClock : public QWidget{
%TypeHeaderCode
#include "analogclock.h"
%End
public:
AnalogClock(QWidget *parent /TransferThis/ = 0);
protected:
virtual void resizeEvent(QResizeEvent *);
virtual void paintEvent(QPaintEvent *e);
};
%End
PyAnalogClock.sip
%Module(name=PyAnalogClock, call_super_init=True, keyword_arguments="Optional")
%DefaultMetatype PyQt5.QtCore.pyqtWrapperType
%DefaultSupertype sip.simplewrapper
%Include AnalogClock.sip
configure.py
is the script that configures the compilation of the project, if you have any problems you must modify some path (it has been tested in Linux)
It is then compiled by executing the following:
python configure.py
make
sudo make install
When executing the previous one it generates a folder called modules, inside of it is the dynamic library, in the case of the example PyAnalogClock.so
, this file we place it in the folder of the source code:
.
├── main.py
└── PyAnalogClock.so
main.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyAnalogClock import AnalogClock
if __name__=="__main__":
import sys
a=QApplication(sys.argv)
w=AnalogClock()
w.show()
sys.exit(a.exec_())
output:
Thank you for your reply. I'm trying to build it, but it fails. python3 configure.py passes, butmake
step says that it cannot find library MyLabel
– Felix
Jun 23 '17 at 19:03
I've reloaded the project. Nowmake
step passes, but when I try to runExamples.main.py
, it gives an error: ImportError: libMyLabel.so.1: cannot open shared object file: No such file or directory
– Felix
Jun 24 '17 at 8:45
Great, it works. I'll try to build it under Windows (with nmake).
– Felix
Jun 25 '17 at 10:39
add a comment |
You can use SIP to create bindings for your C++
code the same way that the PyQt
bindings are made.
However, the bindings generated by SIP are themselves C++
code, and in the case of PyQt
link directly into the Qt
binaries. If you just intend to rewrite PyQt
code as C++
then any speedup realised will be negligible, as very little native python is executed in the first place.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44258808%2fis-it-possible-to-embed-c-widget-to-pyqt-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use SIP to be able to execute a widget created in C ++ from python, in the following link I show an example of how to do it.
The structure of the example is as follows:
├── configure.py
├── sip
│ ├── AnalogClock.sip
│ └── PyAnalogClock.sip
└── src
├── analogclock.cpp
├── analogclock.h
├── analogclockl_global.h
└── AnalogClock.pro
In the src folder you must create the widget library
In the sip folder you must place the structure of the class that you will expose:
AnalogClock.sip
%Import QtGui/QtGuimod.sip
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
class AnalogClock : public QWidget{
%TypeHeaderCode
#include "analogclock.h"
%End
public:
AnalogClock(QWidget *parent /TransferThis/ = 0);
protected:
virtual void resizeEvent(QResizeEvent *);
virtual void paintEvent(QPaintEvent *e);
};
%End
PyAnalogClock.sip
%Module(name=PyAnalogClock, call_super_init=True, keyword_arguments="Optional")
%DefaultMetatype PyQt5.QtCore.pyqtWrapperType
%DefaultSupertype sip.simplewrapper
%Include AnalogClock.sip
configure.py
is the script that configures the compilation of the project, if you have any problems you must modify some path (it has been tested in Linux)
It is then compiled by executing the following:
python configure.py
make
sudo make install
When executing the previous one it generates a folder called modules, inside of it is the dynamic library, in the case of the example PyAnalogClock.so
, this file we place it in the folder of the source code:
.
├── main.py
└── PyAnalogClock.so
main.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyAnalogClock import AnalogClock
if __name__=="__main__":
import sys
a=QApplication(sys.argv)
w=AnalogClock()
w.show()
sys.exit(a.exec_())
output:
Thank you for your reply. I'm trying to build it, but it fails. python3 configure.py passes, butmake
step says that it cannot find library MyLabel
– Felix
Jun 23 '17 at 19:03
I've reloaded the project. Nowmake
step passes, but when I try to runExamples.main.py
, it gives an error: ImportError: libMyLabel.so.1: cannot open shared object file: No such file or directory
– Felix
Jun 24 '17 at 8:45
Great, it works. I'll try to build it under Windows (with nmake).
– Felix
Jun 25 '17 at 10:39
add a comment |
You can use SIP to be able to execute a widget created in C ++ from python, in the following link I show an example of how to do it.
The structure of the example is as follows:
├── configure.py
├── sip
│ ├── AnalogClock.sip
│ └── PyAnalogClock.sip
└── src
├── analogclock.cpp
├── analogclock.h
├── analogclockl_global.h
└── AnalogClock.pro
In the src folder you must create the widget library
In the sip folder you must place the structure of the class that you will expose:
AnalogClock.sip
%Import QtGui/QtGuimod.sip
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
class AnalogClock : public QWidget{
%TypeHeaderCode
#include "analogclock.h"
%End
public:
AnalogClock(QWidget *parent /TransferThis/ = 0);
protected:
virtual void resizeEvent(QResizeEvent *);
virtual void paintEvent(QPaintEvent *e);
};
%End
PyAnalogClock.sip
%Module(name=PyAnalogClock, call_super_init=True, keyword_arguments="Optional")
%DefaultMetatype PyQt5.QtCore.pyqtWrapperType
%DefaultSupertype sip.simplewrapper
%Include AnalogClock.sip
configure.py
is the script that configures the compilation of the project, if you have any problems you must modify some path (it has been tested in Linux)
It is then compiled by executing the following:
python configure.py
make
sudo make install
When executing the previous one it generates a folder called modules, inside of it is the dynamic library, in the case of the example PyAnalogClock.so
, this file we place it in the folder of the source code:
.
├── main.py
└── PyAnalogClock.so
main.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyAnalogClock import AnalogClock
if __name__=="__main__":
import sys
a=QApplication(sys.argv)
w=AnalogClock()
w.show()
sys.exit(a.exec_())
output:
Thank you for your reply. I'm trying to build it, but it fails. python3 configure.py passes, butmake
step says that it cannot find library MyLabel
– Felix
Jun 23 '17 at 19:03
I've reloaded the project. Nowmake
step passes, but when I try to runExamples.main.py
, it gives an error: ImportError: libMyLabel.so.1: cannot open shared object file: No such file or directory
– Felix
Jun 24 '17 at 8:45
Great, it works. I'll try to build it under Windows (with nmake).
– Felix
Jun 25 '17 at 10:39
add a comment |
You can use SIP to be able to execute a widget created in C ++ from python, in the following link I show an example of how to do it.
The structure of the example is as follows:
├── configure.py
├── sip
│ ├── AnalogClock.sip
│ └── PyAnalogClock.sip
└── src
├── analogclock.cpp
├── analogclock.h
├── analogclockl_global.h
└── AnalogClock.pro
In the src folder you must create the widget library
In the sip folder you must place the structure of the class that you will expose:
AnalogClock.sip
%Import QtGui/QtGuimod.sip
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
class AnalogClock : public QWidget{
%TypeHeaderCode
#include "analogclock.h"
%End
public:
AnalogClock(QWidget *parent /TransferThis/ = 0);
protected:
virtual void resizeEvent(QResizeEvent *);
virtual void paintEvent(QPaintEvent *e);
};
%End
PyAnalogClock.sip
%Module(name=PyAnalogClock, call_super_init=True, keyword_arguments="Optional")
%DefaultMetatype PyQt5.QtCore.pyqtWrapperType
%DefaultSupertype sip.simplewrapper
%Include AnalogClock.sip
configure.py
is the script that configures the compilation of the project, if you have any problems you must modify some path (it has been tested in Linux)
It is then compiled by executing the following:
python configure.py
make
sudo make install
When executing the previous one it generates a folder called modules, inside of it is the dynamic library, in the case of the example PyAnalogClock.so
, this file we place it in the folder of the source code:
.
├── main.py
└── PyAnalogClock.so
main.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyAnalogClock import AnalogClock
if __name__=="__main__":
import sys
a=QApplication(sys.argv)
w=AnalogClock()
w.show()
sys.exit(a.exec_())
output:
You can use SIP to be able to execute a widget created in C ++ from python, in the following link I show an example of how to do it.
The structure of the example is as follows:
├── configure.py
├── sip
│ ├── AnalogClock.sip
│ └── PyAnalogClock.sip
└── src
├── analogclock.cpp
├── analogclock.h
├── analogclockl_global.h
└── AnalogClock.pro
In the src folder you must create the widget library
In the sip folder you must place the structure of the class that you will expose:
AnalogClock.sip
%Import QtGui/QtGuimod.sip
%Import QtWidgets/QtWidgetsmod.sip
%If (Qt_5_0_0 -)
class AnalogClock : public QWidget{
%TypeHeaderCode
#include "analogclock.h"
%End
public:
AnalogClock(QWidget *parent /TransferThis/ = 0);
protected:
virtual void resizeEvent(QResizeEvent *);
virtual void paintEvent(QPaintEvent *e);
};
%End
PyAnalogClock.sip
%Module(name=PyAnalogClock, call_super_init=True, keyword_arguments="Optional")
%DefaultMetatype PyQt5.QtCore.pyqtWrapperType
%DefaultSupertype sip.simplewrapper
%Include AnalogClock.sip
configure.py
is the script that configures the compilation of the project, if you have any problems you must modify some path (it has been tested in Linux)
It is then compiled by executing the following:
python configure.py
make
sudo make install
When executing the previous one it generates a folder called modules, inside of it is the dynamic library, in the case of the example PyAnalogClock.so
, this file we place it in the folder of the source code:
.
├── main.py
└── PyAnalogClock.so
main.py
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyAnalogClock import AnalogClock
if __name__=="__main__":
import sys
a=QApplication(sys.argv)
w=AnalogClock()
w.show()
sys.exit(a.exec_())
output:
edited Jun 23 '17 at 21:04
answered May 30 '17 at 11:59
eyllanesc
74.4k103156
74.4k103156
Thank you for your reply. I'm trying to build it, but it fails. python3 configure.py passes, butmake
step says that it cannot find library MyLabel
– Felix
Jun 23 '17 at 19:03
I've reloaded the project. Nowmake
step passes, but when I try to runExamples.main.py
, it gives an error: ImportError: libMyLabel.so.1: cannot open shared object file: No such file or directory
– Felix
Jun 24 '17 at 8:45
Great, it works. I'll try to build it under Windows (with nmake).
– Felix
Jun 25 '17 at 10:39
add a comment |
Thank you for your reply. I'm trying to build it, but it fails. python3 configure.py passes, butmake
step says that it cannot find library MyLabel
– Felix
Jun 23 '17 at 19:03
I've reloaded the project. Nowmake
step passes, but when I try to runExamples.main.py
, it gives an error: ImportError: libMyLabel.so.1: cannot open shared object file: No such file or directory
– Felix
Jun 24 '17 at 8:45
Great, it works. I'll try to build it under Windows (with nmake).
– Felix
Jun 25 '17 at 10:39
Thank you for your reply. I'm trying to build it, but it fails. python3 configure.py passes, but
make
step says that it cannot find library MyLabel– Felix
Jun 23 '17 at 19:03
Thank you for your reply. I'm trying to build it, but it fails. python3 configure.py passes, but
make
step says that it cannot find library MyLabel– Felix
Jun 23 '17 at 19:03
I've reloaded the project. Now
make
step passes, but when I try to run Examples.main.py
, it gives an error: ImportError: libMyLabel.so.1: cannot open shared object file: No such file or directory– Felix
Jun 24 '17 at 8:45
I've reloaded the project. Now
make
step passes, but when I try to run Examples.main.py
, it gives an error: ImportError: libMyLabel.so.1: cannot open shared object file: No such file or directory– Felix
Jun 24 '17 at 8:45
Great, it works. I'll try to build it under Windows (with nmake).
– Felix
Jun 25 '17 at 10:39
Great, it works. I'll try to build it under Windows (with nmake).
– Felix
Jun 25 '17 at 10:39
add a comment |
You can use SIP to create bindings for your C++
code the same way that the PyQt
bindings are made.
However, the bindings generated by SIP are themselves C++
code, and in the case of PyQt
link directly into the Qt
binaries. If you just intend to rewrite PyQt
code as C++
then any speedup realised will be negligible, as very little native python is executed in the first place.
add a comment |
You can use SIP to create bindings for your C++
code the same way that the PyQt
bindings are made.
However, the bindings generated by SIP are themselves C++
code, and in the case of PyQt
link directly into the Qt
binaries. If you just intend to rewrite PyQt
code as C++
then any speedup realised will be negligible, as very little native python is executed in the first place.
add a comment |
You can use SIP to create bindings for your C++
code the same way that the PyQt
bindings are made.
However, the bindings generated by SIP are themselves C++
code, and in the case of PyQt
link directly into the Qt
binaries. If you just intend to rewrite PyQt
code as C++
then any speedup realised will be negligible, as very little native python is executed in the first place.
You can use SIP to create bindings for your C++
code the same way that the PyQt
bindings are made.
However, the bindings generated by SIP are themselves C++
code, and in the case of PyQt
link directly into the Qt
binaries. If you just intend to rewrite PyQt
code as C++
then any speedup realised will be negligible, as very little native python is executed in the first place.
answered May 30 '17 at 10:19
user3419537
2,9371126
2,9371126
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f44258808%2fis-it-possible-to-embed-c-widget-to-pyqt-application%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown