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

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

        <bdo id='2MjXV'></bdo><ul id='2MjXV'></ul>
    1. <small id='2MjXV'></small><noframes id='2MjXV'>

    2. <tfoot id='2MjXV'></tfoot>

        在 PyQt5 中創建復雜的自定義小部件并將其添加到

        Creating a complex custom widget in PyQt5 and adding it to a QGridlayout(在 PyQt5 中創建復雜的自定義小部件并將其添加到 QGridlayout)

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

              <bdo id='zCRNC'></bdo><ul id='zCRNC'></ul>
              • <small id='zCRNC'></small><noframes id='zCRNC'>

                <tfoot id='zCRNC'></tfoot>
                <legend id='zCRNC'><style id='zCRNC'><dir id='zCRNC'><q id='zCRNC'></q></dir></style></legend>

                    <tbody id='zCRNC'></tbody>
                  本文介紹了在 PyQt5 中創建復雜的自定義小部件并將其添加到 QGridlayout的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我必須創建一個如下所示的自定義小部件:

                  I have to create a custom widget that looks like the following:

                  custom_widget_sketch

                  custom_widget_sketch

                  每個自定義小部件代表一個 LIPO 電池,并顯示電池電壓(V)、狀態文本(充電、放電等)、序列號電池(S/N)和三個狀態LED(黃色、綠色和紅色)

                  Each custom widget is a representation of one LIPO battery, and displays the battery volatge (V), status text (charging, discharging, etc), serial number of the battery (S/N) and three status LEDs (yellow, green and red)

                  創建自定義小部件后,我需要在 6*5 的網格中添加其中的 30 個.我在這里的假設是,一旦我創建了自定義小部件,它應該就像在 QGridLayout 中添加一個 QPushButton 一樣簡單,如下所示:

                  After I have created the custom widget I need to add 30 of these in a grid of 6*5. My assumption here is that once I have created that custom widget it should be as simple as adding say a QPushButton in a QGridLayout like so:

                  custom_layput = QGridLayout()
                  custom_layout.addWidget(custom_widget, 0, 0)
                  custom_layout.addWidget(custom_widget, 0, 1)
                  
                  .
                  .
                  .
                  
                  custom_layout.addWidget(custom_widget, 6, 5)
                  

                  最終屏幕如下所示:

                  main_window_sketch

                  main_window_sketch

                  考慮到所有這些要求,我有以下問題:

                  Considering all of these requirements I have the following questions:

                  1. 我能否使用 PyQt5 創建如此復雜/豐富的自定義小部件?可行嗎?
                  2. 這是創建自定義小部件的正確方法嗎:首先使用 QPainter 繪制一個正方形(這是 custom_widget_sketch 中的藍色正方形),然后添加 QLineEdits 以顯示電壓 (V) 文本、序列號 (S/N)文本和狀態文本,添加一個 QLabel 用于在自定義小部件中顯示V"、S/N"和STATUS"標簽,然后繪制三個圓圈:黃色、綠色和紅色 LED 各一個,然后使用 QVBoxLayout 和 QHBoxLayout 的組合來排列 QLineEditsQLabels、正方形和圓形(LED 指示燈)
                  3. 如何打包這個自定義小部件,以便我可以像添加 QPushButtonQLineEdit 一樣簡單地將其添加到布局中?
                  1. Will I able able to create such a complex/rich custom widget using PyQt5? Is it doable?
                  2. Is this the correct approach to create the custom widget: first draw a square using QPainter (this is the blue square in the custom_widget_sketch), then add QLineEdits to dispaly the voltage (V) text, serial number (S/N) text and the Status text, add a QLabel for displaying the "V", "S/N" and "STATUS" labels in the custom widget, then draw the three circles: one each for the yellow, green and red LEDs, then use a combination of QVBoxLayout and QHBoxLayout to arrange the QLineEdits, QLabels, the square and the circles (LED indicators)
                  3. How do I package this custom widget such that I can simply add it to a layout like I would add a QPushButton or a QLineEdit?

                  PS:custom_widget_sketch 在左上角還包含一條線和一個正方形,里面有三條線.這是為了描述 LIPO 電池的連接器.現在實施它可能太復雜了.因此,即使我能夠實現這兩個元素以外的所有內容,我也會很高興

                  PS: The custom_widget_sketch also contains a line and a square with three lines inside it in the top left corner. This is to depict the connector for the LIPO battery. It may be too complex to implement that right now. So I would be happy even if I am able to implement everything other than these two elements

                  我已經解決了一些 SO 問題,但它們都參考了一個教程,這不是我的最終目標.

                  I have been through a few SO questions but they all refer to one tutorial, which is not my end goal.

                  我希望能提供任何代碼片段、代碼概要/要遵循的步驟或任何文章/教程的鏈接,這些文章/教程創建了類似于我希望創建的自定義小部件.

                  I would appreciate any code snippets, general outline of code/steps to follow or links to any articles/tutorials that create custom widgets similar to the one I wish to create.

                  推薦答案

                  我最終創建的自定義小部件的 Python 代碼.小部件如下所示:

                  Python code for the custom widget I ended up creating. The widget looks as follows:

                  from PyQt5.QtGui import QPainter, QPen,QBrush,QColor
                  from PyQt5.QtCore import Qt
                  from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QHBoxLayout,QPushButton, QLineEdit, QLabel, QVBoxLayout, QHBoxLayout, QSizePolicy, QGroupBox
                  import sys
                  
                  class BatteryStatusWidget(QWidget):
                      def __init__(self):
                          super(BatteryStatusWidget, self).__init__()
                          #Voltage widgets
                          self.voltage_text = QLineEdit()
                          self.voltage_text.setReadOnly(True)
                          self.voltage_label = QLabel("V")
                          self.voltage_label.setStyleSheet("QLabel {color : white}")
                  
                          #Status widgets
                          self.status_text = QLineEdit()
                          self.status_text.setReadOnly(True)
                          self.status_label = QLabel("STATUS")
                          self.status_label_font = QtGui.QFont()
                          self.status_label_font.setPointSize(12)
                          self.status_label.setFont(self.status_label_font)
                          self.status_label.setAlignment(QtCore.Qt.AlignCenter)
                          self.status_label.setStyleSheet("QLabel {color : white}")
                  
                          #Serial number
                          self.serial_number_text = QLineEdit()
                          self.serial_number_label = QLabel("S/N")
                  
                          #LED widgets
                          self.yellow_led_label = QLabel()
                          self.yellow_led_label.setStyleSheet("QLabel {background-color : yellow; border-color : black; border-width : 1px; border-style : solid; border-radius : 10px; min-height: 20px; min-width: 20px}")
                          self.green_led_label = QLabel()
                          self.green_led_label.setStyleSheet("QLabel {background-color : green; border-color : black; border-width : 1px; border-style : solid; border-radius : 10px; min-height: 20px; min-width: 20px}")
                          self.red_led_label = QLabel()
                          self.red_led_label.setStyleSheet("QLabel {background-color : red; border-color : black; border-width : 1px; border-style : solid; border-radius : 10px; min-height: 20px; min-width: 20px}")
                  
                          #Number Identifier Label
                          #This label is for tagging the widget with the same label as on the PCB
                          self.number_label = QLabel("Test")
                          self.number_label.setAlignment(QtCore.Qt.AlignCenter)
                          self.number_label_font = QtGui.QFont()
                          self.number_label_font.setPointSize(12)
                          self.number_label_font.setBold(True)
                          self.number_label.setFont(self.number_label_font)
                  
                          #Layouts
                          #voltage layout
                          self.voltage_layout = QHBoxLayout()
                          self.voltage_layout.addWidget(self.voltage_text)
                          self.voltage_layout.addWidget(self.voltage_label)
                  
                          #Serial number layout
                          self.serial_num_layout = QHBoxLayout()
                          self.serial_num_layout.addWidget(self.serial_number_label)
                          self.serial_num_layout.addWidget(self.serial_number_text)
                  
                          #Voltage and status box layouts
                          self.blue_container = QWidget()
                          self.blue_container.setStyleSheet("background-color:rgb(77, 122, 194);")
                          self.blue_box_layout = QVBoxLayout()
                          self.blue_box_layout.addLayout(self.voltage_layout)
                          self.blue_box_layout.addWidget(self.status_text)
                          self.blue_box_layout.addWidget(self.status_label)
                          self.blue_container.setLayout(self.blue_box_layout)
                  
                  
                          #Blue box+ serial num layout
                          self.non_led_layout = QVBoxLayout()
                          #self.non_led_layout.addWidget(self.number_label)
                          self.non_led_layout.addWidget(self.blue_container)
                          self.non_led_layout.addLayout(self.serial_num_layout)
                  
                          #LED layout
                          self.led_layout = QVBoxLayout()
                          self.led_layout.addWidget(self.yellow_led_label)
                          self.led_layout.addWidget(self.green_led_label)
                          self.led_layout.addWidget(self.red_led_label)
                          self.led_layout.addStretch(1)
                  
                          #Main Layout
                          self.main_layout = QHBoxLayout()
                          self.main_layout.addLayout(self.non_led_layout)
                          self.main_layout.addLayout(self.led_layout)
                  
                          #Main group box
                          self.main_group_box = QGroupBox()
                          self.main_group_box.setStyleSheet("QGroupBox{font-size: 10px}")
                          self.main_group_box.setTitle("Chan #")
                          self.main_group_box.setLayout(self.main_layout)
                  
                          #Outer main layout to accomodate the group box
                          self.outer_main_layout = QVBoxLayout()
                          self.outer_main_layout.addWidget(self.main_group_box)
                  
                          #Set the main layout
                          self.setLayout(self.outer_main_layout)
                          self.setWindowTitle("Battery Widget")
                  
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      main_window = BatteryStatusWidget()
                      main_window.show()
                      app.exec_()
                  

                  正如我在問題中發布的那樣,我能夠輕松創建 30 個自定義小部件實例并將其添加到 QGridLayout 中.最終的 GUI 屏幕如下所示:

                  I was able to easily create 30 instances of the custom widget and add it to a QGridLayout as I posted in my question. The final GUI screen looks as follows:

                  這篇關于在 PyQt5 中創建復雜的自定義小部件并將其添加到 QGridlayout的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數綁定到 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 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                  `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                    <bdo id='ge1tZ'></bdo><ul id='ge1tZ'></ul>
                    <legend id='ge1tZ'><style id='ge1tZ'><dir id='ge1tZ'><q id='ge1tZ'></q></dir></style></legend>

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

                          <tbody id='ge1tZ'></tbody>
                        <tfoot id='ge1tZ'></tfoot>

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

                            主站蜘蛛池模板: 婷婷久久精品一区二区 | 天天操夜夜操 | 日韩精品在线观看一区二区 | 成人黄色电影在线观看 | 久久久国产精品 | 国产免费人成xvideos视频 | 成人在线免费观看av | 蜜桃视频在线观看免费视频网站www | 精品国产一区二区三区久久狼黑人 | av激情在线 | 在线a视频 | 国产色爽 | 超碰成人免费 | 久久伊 | 一级片在线观看 | 精品国产乱码久久久久久闺蜜 | 日日操夜夜操天天操 | 综合久久99 | 日韩免费av | 欧美成人视屏 | 黄色在线免费观看 | 逼逼网 | 91美女在线 | 美女国内精品自产拍在线播放 | 午夜在线免费观看 | 99精品视频一区二区三区 | 99久久精品国产毛片 | 欧美一区二区在线免费观看 | 亚洲福利网 | 91免费视频观看 | 一级在线观看 | 九九热这里只有精品在线观看 | 国产精品国产三级国产播12软件 | 男女久久久 | 日韩中文字幕在线视频 | 91精品久久久久久久久久入口 | 天天天天天天天干 | 欧美日韩在线视频一区 | 亚洲第一天堂无码专区 | a毛片 | 亚洲一区精品在线 |