久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='WLS5K'><style id='WLS5K'><dir id='WLS5K'><q id='WLS5K'></q></dir></style></legend>

      1. <tfoot id='WLS5K'></tfoot>

          <bdo id='WLS5K'></bdo><ul id='WLS5K'></ul>

      2. <small id='WLS5K'></small><noframes id='WLS5K'>

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

        我在哪里為 Qt 設(shè)計器的單個提升 QWidget 編寫類

        where do I write the class for a single promoted QWidget from Qt designer(我在哪里為 Qt 設(shè)計器的單個提升 QWidget 編寫類)
          <bdo id='ktSvE'></bdo><ul id='ktSvE'></ul>

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

            <tfoot id='ktSvE'></tfoot>
                  <tbody id='ktSvE'></tbody>
                <i id='ktSvE'><tr id='ktSvE'><dt id='ktSvE'><q id='ktSvE'><span id='ktSvE'><b id='ktSvE'><form id='ktSvE'><ins id='ktSvE'></ins><ul id='ktSvE'></ul><sub id='ktSvE'></sub></form><legend id='ktSvE'></legend><bdo id='ktSvE'><pre id='ktSvE'><center id='ktSvE'></center></pre></bdo></b><th id='ktSvE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ktSvE'><tfoot id='ktSvE'></tfoot><dl id='ktSvE'><fieldset id='ktSvE'></fieldset></dl></div>
                <legend id='ktSvE'><style id='ktSvE'><dir id='ktSvE'><q id='ktSvE'></q></dir></style></legend>

                  本文介紹了我在哪里為 Qt 設(shè)計器的單個提升 QWidget 編寫類的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我閱讀、測試和理解了很多 Qt 設(shè)計器的 QWidgets 使用示例,這些示例被提升為 PyQt5.盡管如此,我無法為自己處理一個簡單的例子.

                  I read, test and understand a lot of examples for usage of QWidgets from Qt designer, which are promoted to PyQt5. Nevertheless I am not able to deal with a simple example for my own.

                  下面我展示了我的代碼,它不起作用并嘗試解釋.

                  Beneath I show my code, which is not working and try to explain.

                  在 Qt 設(shè)計器中,我創(chuàng)建了一個簡單的 QMainWindow,命名為標準化的 MainWindow

                  in Qt desginer i create a simple QMainWindow, named standardized as MainWindow

                  在我創(chuàng)建單個標簽 QLabel.我將其提升為neuLabel"類并將其命名為 labelqt.帶有 Add 、標題 neulabel.h 和提升的窗口 --> 一切都很好.

                  Within I create a single label QLabel. This I promote to class "neuLabel" and name it labelqt. The window with, Add , the header neulabel.h and promote --> everything is fine.

                  我明白,我必須為類 neuLabel 編寫代碼.但是:在哪里做呢?

                  I understand, that I have to write code for the class neuLabel. But: WHERE to do it?

                  通過非常簡單的示例,我嘗試了這樣的:

                  With very simple example I tried it like this:

                  from PyQt5 import QtWidgets, uic
                  import sys
                  uifile_1 = 'testpromote.ui'
                  form_1, base_1 = uic.loadUiType(uifile_1)
                  class neuLabel(QLabel, QPixmap):
                      def __init__(self,title,pixmap,parent):
                      super().__init__(title,parent)
                      self.setAcceptDrops(True)
                  def mousePressEvent(self, e):
                      QLabel.mousePressEvent(self, e)
                      if e.button() == QtCore.Qt.LeftButton:
                          print('press')
                  class myApp(base_1, form_1):
                      def __init__(self):
                          super(base_1,self).__init__()
                          self.setupUi(self)
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      ex = myApp()   #Dialog()
                      ex.show()
                  sys.exit(app.exec_())
                  

                  錯誤是這樣的

                  Traceback (most recent call last):
                    File "/home/jf/PycharmProjects/myMuhaInp/testpromote.py", line 5, in <module>
                      form_1, base_1 = uic.loadUiType(uifile_1)
                    File "/usr/lib/python3/dist-packages/PyQt5/uic/__init__.py", line 201, in loadUiType
                      exec(code_string.getvalue(), ui_globals)
                    File "<string>", line 37, in <module>
                  ModuleNotFoundError: No module named 'neulabel'
                  

                  我真的不明白,在哪里對類neulabel進行編碼(我確實嘗試了很多示例.(在沒有示例中,我發(fā)現(xiàn),是單個QWidget的推廣)

                  I really don't understand, WHERE to code the class neulabel (and I really tried a lot of examples. (In no example, I found, is the promotion of a single QWidget)

                  推薦答案

                  在你所有的代碼出現(xiàn)錯誤之前:為什么需要一個繼承自 QLabel 和 QPixmap 的類?我不明白這一點,QLabel 使用 QPixmap(composition),QLabel is 不是 QPixmap(inherency).

                  Before all your code has an error: Why do you need a class that inherits from QLabel and QPixmap? I don't see the point, a QLabel uses a QPixmap(composition), a QLabel is not a QPixmap(inherency).

                  對于要提升的小部件,它必須具有以下規(guī)則(我在文檔中沒有找到它們):

                  For a widget to be promoted it must have the following rules (I did not find them in the docs):

                  • 小部件的構(gòu)造函數(shù)必須有一個參數(shù),并且必須是父級.

                  • The constructor of the widget must have a single parameter and must be the parent.

                  該類不能在使用它的同一文件中,因為它可以創(chuàng)建循環(huán)導入.

                  The class must not be in the same file where it is used since it can create a circular import.

                  小部件促銷表單要求提供 2 個數(shù)據(jù):

                  The widget promotion form asks for 2 data:

                  1. 提升的類名,必須是類名.
                  2. 頭文件 必須是類所在文件的位置(在 C++ 中,根據(jù)自定義規(guī)則,文件名與類名相同,但使用小寫字母,但在 python 中不符合).

                  1. Promoted class name which must be the name of the class.
                  2. Header file which must be the location of the file where the class is (in C++ by custom rule the name of the file is the same name of the class but with lowercase letters, but in python it does not comply).

                  例如,如果FooClass"被放置為Promoted class name并且a/b/c"或abc"被放置在頭文件中,它將被翻譯到 from abc import Foo 確認這是正確的.

                  For example if "FooClass" is placed as Promoted class name and "a/b/c" or "a.b.c" is placed in Header file it will be translated to from a.b.c import Foo so verify that this is correct.

                  示例:

                  考慮到上述情況,最簡單的實現(xiàn)是創(chuàng)建一個.py,其中要提升的類是:

                  Considering the above, the simplest implementation is to create a .py where the class to be promoted is:

                  neulabel.py

                  from PyQt5 import QtCore, QtWidgets
                  
                  
                  class NeuLabel(QtWidgets.QLabel):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.setAcceptDrops(True)
                  
                      def mousePressEvent(self, e):
                          super().mousePressEvent(e)
                          if e.button() == QtCore.Qt.LeftButton:
                              print("press")
                  

                  然后在.ui中你必須在表格中填寫以下內(nèi)容,按添加"按鈕,然后按推廣"按鈕

                  Then in the .ui you must fill in the following in the form, press the "Add" button and then the "Promote" button

                  生成以下 .ui:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <ui version="4.0">
                   <class>MainWindow</class>
                   <widget class="QMainWindow" name="MainWindow">
                    <property name="geometry">
                     <rect>
                      <x>0</x>
                      <y>0</y>
                      <width>800</width>
                      <height>600</height>
                     </rect>
                    </property>
                    <property name="windowTitle">
                     <string>MainWindow</string>
                    </property>
                    <widget class="QWidget" name="centralwidget">
                     <widget class="NeuLabel" name="label">
                      <property name="geometry">
                       <rect>
                        <x>120</x>
                        <y>160</y>
                        <width>251</width>
                        <height>191</height>
                       </rect>
                      </property>
                      <property name="text">
                       <string>TextLabel</string>
                      </property>
                     </widget>
                    </widget>
                    <widget class="QMenuBar" name="menubar">
                     <property name="geometry">
                      <rect>
                       <x>0</x>
                       <y>0</y>
                       <width>800</width>
                       <height>26</height>
                      </rect>
                     </property>
                    </widget>
                    <widget class="QStatusBar" name="statusbar"/>
                   </widget>
                   <customwidgets>
                    <customwidget>
                     <class>NeuLabel</class>
                     <extends>QLabel</extends>
                     <header>neulabel</header>
                    </customwidget>
                   </customwidgets>
                   <resources/>
                   <connections/>
                  </ui>
                  

                  然后在主文件中使用:

                  import os
                  import sys
                  
                  from PyQt5 import QtWidgets, uic
                  
                  CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
                  
                  uifile_1 = os.path.join(CURRENT_DIR, "testpromote.ui")
                  form_1, base_1 = uic.loadUiType(uifile_1)
                  
                  
                  class myApp(base_1, form_1):
                      def __init__(self):
                          super(base_1, self).__init__()
                          self.setupUi(self)
                  
                  
                  if __name__ == "__main__":
                      app = QtWidgets.QApplication(sys.argv)
                      ex = myApp()
                      ex.show()
                      sys.exit(app.exec_())
                  

                  ├── main.py
                  ├── neulabel.py
                  └── testpromote.ui
                  

                  這篇關(guān)于我在哪里為 Qt 設(shè)計器的單個提升 QWidget 編寫類的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 Qt 菜單欄中的操作?)
                  PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                  How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設(shè)置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應(yīng)該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構(gòu)造函數(shù)有未知關(guān)鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)

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

                    <tbody id='RHyV4'></tbody>
                  1. <i id='RHyV4'><tr id='RHyV4'><dt id='RHyV4'><q id='RHyV4'><span id='RHyV4'><b id='RHyV4'><form id='RHyV4'><ins id='RHyV4'></ins><ul id='RHyV4'></ul><sub id='RHyV4'></sub></form><legend id='RHyV4'></legend><bdo id='RHyV4'><pre id='RHyV4'><center id='RHyV4'></center></pre></bdo></b><th id='RHyV4'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RHyV4'><tfoot id='RHyV4'></tfoot><dl id='RHyV4'><fieldset id='RHyV4'></fieldset></dl></div>
                  2. <legend id='RHyV4'><style id='RHyV4'><dir id='RHyV4'><q id='RHyV4'></q></dir></style></legend>
                        <bdo id='RHyV4'></bdo><ul id='RHyV4'></ul>
                          1. <tfoot id='RHyV4'></tfoot>
                          2. 主站蜘蛛池模板: 中文二区 | 成人午夜免费网站 | 免费中文字幕日韩欧美 | 一本一道久久a久久精品综合蜜臀 | 久久久久久国产精品 | 在线播放国产一区二区三区 | 欧美成人激情 | 天堂色 | 日韩午夜影院 | 91精品综合久久久久久五月天 | 国产aⅴ精品 | 免费一区二区三区在线视频 | 99re视频这里只有精品 | 欧美日韩亚洲国产 | 国产网站在线免费观看 | 成人免费一级视频 | 欧美视频日韩 | 欧美久久一级特黄毛片 | 精品九九九 | 久在线| 红色av社区| 欧美男人天堂 | 成人在线精品视频 | 性一交一乱一透一a级 | 狠狠干2020| 在线免费观看成人 | 九九久久久| 国产高清久久久 | 欧美中文字幕 | 国产亚洲精品美女久久久久久久久久 | 午夜欧美一区二区三区在线播放 | 国产日韩精品一区 | 成人av一区| 国产精品日韩一区二区 | 亚洲免费视频网站 | 国产精品美女视频 | 日韩中文字幕视频在线 | 国产目拍亚洲精品99久久精品 | 在线免费观看视频你懂的 | 精品久久久久久久久久久久 | 天堂网中文字幕在线观看 |