<bdo id='oDiPH'></bdo><ul id='oDiPH'></ul>
      <tfoot id='oDiPH'></tfoot>
      1. <i id='oDiPH'><tr id='oDiPH'><dt id='oDiPH'><q id='oDiPH'><span id='oDiPH'><b id='oDiPH'><form id='oDiPH'><ins id='oDiPH'></ins><ul id='oDiPH'></ul><sub id='oDiPH'></sub></form><legend id='oDiPH'></legend><bdo id='oDiPH'><pre id='oDiPH'><center id='oDiPH'></center></pre></bdo></b><th id='oDiPH'></th></span></q></dt></tr></i><div id='oDiPH'><tfoot id='oDiPH'></tfoot><dl id='oDiPH'><fieldset id='oDiPH'></fieldset></dl></div>
      2. <small id='oDiPH'></small><noframes id='oDiPH'>

        <legend id='oDiPH'><style id='oDiPH'><dir id='oDiPH'><q id='oDiPH'></q></dir></style></legend>

      3. 是否可以将 C++ 小部件嵌入 PyQt 应用程序?

        时间:2023-12-02
        <legend id='Jpdfl'><style id='Jpdfl'><dir id='Jpdfl'><q id='Jpdfl'></q></dir></style></legend>

        • <bdo id='Jpdfl'></bdo><ul id='Jpdfl'></ul>

            <i id='Jpdfl'><tr id='Jpdfl'><dt id='Jpdfl'><q id='Jpdfl'><span id='Jpdfl'><b id='Jpdfl'><form id='Jpdfl'><ins id='Jpdfl'></ins><ul id='Jpdfl'></ul><sub id='Jpdfl'></sub></form><legend id='Jpdfl'></legend><bdo id='Jpdfl'><pre id='Jpdfl'><center id='Jpdfl'></center></pre></bdo></b><th id='Jpdfl'></th></span></q></dt></tr></i><div id='Jpdfl'><tfoot id='Jpdfl'></tfoot><dl id='Jpdfl'><fieldset id='Jpdfl'></fieldset></dl></div>

                <tbody id='Jpdfl'></tbody>

              <small id='Jpdfl'></small><noframes id='Jpdfl'>

                • <tfoot id='Jpdfl'></tfoot>
                  本文介绍了是否可以将 C++ 小部件嵌入 PyQt 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 PyQt5 应用程序和大多数用 Python 编写的小部件.我想用 C++ Qt 编写一些小部件以使其更快,然后将其嵌入到我的 PyQt QMainWindow 中.

                  有可能吗?

                  解决方案

                  您可以使用 SIP 来从 python 执行用 C++ 创建的小部件,在下面的

                  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?

                  解决方案

                  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:

                  这篇关于是否可以将 C++ 小部件嵌入 PyQt 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:是否有一个相当于 NullPointerException 的 C++ 下一篇:从内存缓冲区创建 HBITMAP

                  相关文章

                  <small id='h9vzC'></small><noframes id='h9vzC'>

                    <tfoot id='h9vzC'></tfoot>

                    • <bdo id='h9vzC'></bdo><ul id='h9vzC'></ul>

                      <i id='h9vzC'><tr id='h9vzC'><dt id='h9vzC'><q id='h9vzC'><span id='h9vzC'><b id='h9vzC'><form id='h9vzC'><ins id='h9vzC'></ins><ul id='h9vzC'></ul><sub id='h9vzC'></sub></form><legend id='h9vzC'></legend><bdo id='h9vzC'><pre id='h9vzC'><center id='h9vzC'></center></pre></bdo></b><th id='h9vzC'></th></span></q></dt></tr></i><div id='h9vzC'><tfoot id='h9vzC'></tfoot><dl id='h9vzC'><fieldset id='h9vzC'></fieldset></dl></div>

                    1. <legend id='h9vzC'><style id='h9vzC'><dir id='h9vzC'><q id='h9vzC'></q></dir></style></legend>