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

    • <bdo id='36Qks'></bdo><ul id='36Qks'></ul>

      <tfoot id='36Qks'></tfoot>

      <small id='36Qks'></small><noframes id='36Qks'>

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

        Qt Designer和PyQt程序中verticalLayout的大小不同

        Size of verticalLayout is different in Qt Designer and PyQt program(Qt Designer和PyQt程序中verticalLayout的大小不同)
        <tfoot id='0LqV6'></tfoot>

            <tbody id='0LqV6'></tbody>

            <bdo id='0LqV6'></bdo><ul id='0LqV6'></ul>
            • <legend id='0LqV6'><style id='0LqV6'><dir id='0LqV6'><q id='0LqV6'></q></dir></style></legend>

                <small id='0LqV6'></small><noframes id='0LqV6'>

                  <i id='0LqV6'><tr id='0LqV6'><dt id='0LqV6'><q id='0LqV6'><span id='0LqV6'><b id='0LqV6'><form id='0LqV6'><ins id='0LqV6'></ins><ul id='0LqV6'></ul><sub id='0LqV6'></sub></form><legend id='0LqV6'></legend><bdo id='0LqV6'><pre id='0LqV6'><center id='0LqV6'></center></pre></bdo></b><th id='0LqV6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='0LqV6'><tfoot id='0LqV6'></tfoot><dl id='0LqV6'><fieldset id='0LqV6'></fieldset></dl></div>
                • 本文介紹了Qt Designer和PyQt程序中verticalLayout的大小不同的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  在 Qt Designer 5.9 中 test.ui 中的 verticalLayout 與窗口邊緣有一定距離,但在加載 test.uimain.py 中使用 PyQt 5.11.3,verticalLayout 會擴(kuò)展到窗口的邊緣.

                  In Qt Designer 5.9 the verticalLayout in test.ui had a certain distance to the edge of the window, but after loading test.ui with PyQt 5.11.3 in main.py the verticalLayout extend to the edge of the window.

                  ma??in.py:

                      #!/usr/bin/python3
                  import sys
                  from PyQt5.QtWidgets import QApplication, QMainWindow
                  from PyQt5.uic import loadUi
                  
                  class MainWindow(QMainWindow):
                      def __init__(self, parent=None):
                          super().__init__()
                          loadUi("test.ui", self)
                  
                  def main():
                      app = QApplication(sys.argv)
                      main_window = MainWindow(app)
                      main_window.show()
                      sys.exit(app.exec_())
                  
                  
                  if __name__ == "__main__":
                  main()
                  

                  test.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>350</width>
                      <height>257</height>
                     </rect>
                    </property>
                    <property name="windowTitle">
                     <string>Test</string>
                    </property>
                    <widget class="QWidget" name="centralwidget">
                     <layout class="QGridLayout" name="gridLayout_2">
                      <item row="0" column="0">
                       <layout class="QVBoxLayout" name="verticalLayout">
                        <property name="leftMargin">
                         <number>0</number>
                        </property>
                        <property name="topMargin">
                         <number>0</number>
                        </property>
                        <item>
                         <spacer name="verticalSpacer_2">
                          <property name="orientation">
                           <enum>Qt::Vertical</enum>
                          </property>
                          <property name="sizeHint" stdset="0">
                           <size>
                            <width>20</width>
                            <height>40</height>
                           </size>
                          </property>
                         </spacer>
                        </item>
                        <item>
                         <widget class="QGroupBox" name="groupBox">
                          <layout class="QGridLayout" name="gridLayout">
                           <item row="1" column="1">
                            <widget class="QSpinBox" name="spinBox">
                             <property name="maximum">
                              <number>100000</number>
                             </property>
                             <property name="value">
                              <number>1000</number>
                             </property>
                            </widget>
                           </item>
                           <item row="1" column="0">
                            <widget class="QLabel" name="label_2">
                             <property name="text">
                              <string>Test</string>
                             </property>
                             <property name="alignment">
                              <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
                             </property>
                            </widget>
                           </item>
                           <item row="0" column="1">
                            <widget class="QComboBox" name="comboBox">
                             <property name="currentText">
                              <string/>
                             </property>
                            </widget>
                           </item>
                           <item row="0" column="0">
                            <widget class="QLabel" name="label1">
                             <property name="text">
                              <string>Test</string>
                             </property>
                             <property name="alignment">
                              <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
                             </property>
                            </widget>
                           </item>
                          </layout>
                         </widget>
                        </item>
                        <item>
                         <spacer name="verticalSpacer">
                          <property name="orientation">
                           <enum>Qt::Vertical</enum>
                          </property>
                          <property name="sizeHint" stdset="0">
                           <size>
                            <width>20</width>
                            <height>40</height>
                           </size>
                          </property>
                         </spacer>
                        </item>
                        <item>
                         <widget class="QPushButton" name="pushButton">
                          <property name="layoutDirection">
                           <enum>Qt::LeftToRight</enum>
                          </property>
                          <property name="text">
                           <string>Test</string>
                          </property>
                         </widget>
                        </item>
                       </layout>
                      </item>
                     </layout>
                    </widget>
                    <widget class="QMenuBar" name="menubar">
                     <property name="geometry">
                      <rect>
                       <x>0</x>
                       <y>0</y>
                       <width>350</width>
                       <height>28</height>
                      </rect>
                     </property>
                    </widget>
                    <widget class="QStatusBar" name="statusbar"/>
                   </widget>
                   <resources/>
                   <connections/>
                  </ui>
                  

                  <小時(shí)>

                  Qt Designer 5.9 中 test.ui 的屏幕截圖:

                  main.py 加載 test.ui 的截圖:

                  這種行為的原因是什么?

                  What's the reason for this behavior?

                  推薦答案

                  查看uic.loadUi()的代碼會發(fā)現(xiàn)如下代碼:

                  If you check the code of uic.loadUi() you will find the following code:

                  uiparser.py

                  class UIParser(object):  
                      # ...
                      def createLayout(self, elem):
                          # ...
                          margin = -1 if self.stack.topIsLayout() else self.defaults['margin']
                          margin = self.wprops.getProperty(elem, 'margin', margin)
                          left = self.wprops.getProperty(elem, 'leftMargin', margin)
                          top = self.wprops.getProperty(elem, 'topMargin', margin)
                          right = self.wprops.getProperty(elem, 'rightMargin', margin)
                          bottom = self.wprops.getProperty(elem, 'bottomMargin', margin)
                          # A layout widget should, by default, have no margins.
                          if self.stack.topIsLayoutWidget():
                              if left < 0: left = 0
                              if top < 0: top = 0
                              if right < 0: right = 0
                              if bottom < 0: bottom = 0
                  
                      def topIsLayoutWidget(self):
                          # A plain QWidget is a layout widget unless it's parent is a
                          # QMainWindow or a container widget.  Note that the corresponding uic
                          # test is a little more complicated as it involves features not
                          # supported by pyuic.
                  
                          if type(self[-1]) is not QtWidgets.QWidget:
                              return False
                  
                          if len(self) < 2:
                              return False
                  
                          parent = self[-2]
                  
                          return isinstance(parent, QtWidgets.QWidget) and type(parent) not in (
                                  QtWidgets.QMainWindow,
                                  QtWidgets.QStackedWidget,
                                  QtWidgets.QToolBox,
                                  QtWidgets.QTabWidget,
                                  QtWidgets.QScrollArea,
                                  QtWidgets.QMdiArea,
                                  QtWidgets.QWizard,
                                  QtWidgets.QDockWidget)
                  

                  問題是由 topIsLayoutWidget() 函數(shù)引起的,因?yàn)楦讣墝⒁糜米骰A(chǔ)的小部件,在這種情況下 MainWindow 符合 isinstance(parent, QtWidgets.QWidget) 和類型 (parent) not in (QtWidgets.QMainWindow, ...) 所以 topIsLayoutWidget() 將返回 True,所以左、上、右、下為 -1由于這些屬性不存在將被更新為 0,因此將通過消除默認(rèn)值 (9, 9, 9, 9) 來建立對 contentsMargins 的應(yīng)用,但在 Qt Designer 的情況下, contentsMarginscode>contentsMargins 尚未更新,保持其默認(rèn)值.

                  The problem is caused by the topIsLayoutWidget() function since the parent will refer to the widget that is used as a base, in this case MainWindow complies with isinstance(parent, QtWidgets.QWidget) and type (parent) not in (QtWidgets.QMainWindow, ...) so topIsLayoutWidget() will return True, so to be left, top, right, bottom be -1 since those properties do not exist will be updated to 0 so the apply to contentsMargins will be established by eliminating the default value (9, 9, 9, 9), but in the case of Qt Designer the contentsMargins have not been updated maintaining their default value.

                  所以總之是一個(gè) pyqt 錯(cuò)誤,它也在評論中指出:

                  So in conclusion is a pyqt bug that also points in the comments:

                  # ... Note that the corresponding uic
                  # test is a little more complicated as it involves features not
                  # supported by pyuic.*
                  

                  所以有幾種解決方案:

                  • 刪除:

                  if self.stack.topIsLayoutWidget():
                      if left < 0: left = 0
                      if top < 0: top = 0
                      if right < 0: right = 0
                      if bottom < 0: bottom = 0
                  

                • 使用uic.loadUiType():

                  #!/usr/bin/python3
                  import sys
                  from PyQt5 import QtCore, QtWidgets, uic
                  
                  Ui_Interface, _ = uic.loadUiType('test.ui')
                  
                  class MainWindow(QtWidgets.QMainWindow, Ui_Interface):
                      def __init__(self, parent=None):
                          super().__init__(parent)
                          self.setupUi(self)
                  
                  def main():
                      app = QtWidgets.QApplication(sys.argv)
                      main_window = MainWindow()
                      main_window.show()
                      sys.exit(app.exec_())
                  
                  if __name__ == "__main__":
                      main()
                  

                • 我更喜歡第二種解決方案,因?yàn)椴粦?yīng)修改源代碼.

                  I prefer the second solution since the source code should not be modified.

                  這篇關(guān)于Qt Designer和PyQt程序中verticalLayout的大小不同的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 啟動后進(jìn)度躍升至 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 刻度標(biāo)簽設(shè)置在固定位置,以便當(dāng)我向左或向右滾動時(shí),yaxis 刻度標(biāo)簽應(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時(shí)顯示進(jìn)度條?)
                  1. <i id='6BTCt'><tr id='6BTCt'><dt id='6BTCt'><q id='6BTCt'><span id='6BTCt'><b id='6BTCt'><form id='6BTCt'><ins id='6BTCt'></ins><ul id='6BTCt'></ul><sub id='6BTCt'></sub></form><legend id='6BTCt'></legend><bdo id='6BTCt'><pre id='6BTCt'><center id='6BTCt'></center></pre></bdo></b><th id='6BTCt'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='6BTCt'><tfoot id='6BTCt'></tfoot><dl id='6BTCt'><fieldset id='6BTCt'></fieldset></dl></div>
                  2. <legend id='6BTCt'><style id='6BTCt'><dir id='6BTCt'><q id='6BTCt'></q></dir></style></legend><tfoot id='6BTCt'></tfoot>
                      <tbody id='6BTCt'></tbody>

                      • <small id='6BTCt'></small><noframes id='6BTCt'>

                            <bdo id='6BTCt'></bdo><ul id='6BTCt'></ul>

                            主站蜘蛛池模板: 欧美日韩精品一区 | 久久久福利 | 成人一区二区三区视频 | 91精品一区二区三区久久久久 | 亚洲女人天堂网 | 亚洲成人网在线 | 国产精品精品久久久久久 | 国产一区| 丝袜 亚洲 另类 欧美 综合 | 免费国产一区二区视频 | 成人在线精品视频 | 久久y| 国产成人99久久亚洲综合精品 | 成人在线中文字幕 | 精品久久久久久久久久久 | 综合欧美亚洲 | 全免费a级毛片免费看视频免费下 | 精品天堂| 国产精品福利在线 | 男女羞羞视频大全 | 国产成人免费一区二区60岁 | 久久夜视频 | 青青草华人在线视频 | 91精品国产欧美一区二区成人 | 久久精品欧美一区二区三区不卡 | 亚洲精品一二区 | 99re热精品视频 | 亚洲欧美一区二区三区国产精品 | 99久久精品免费看国产四区 | 精品欧美一区二区在线观看视频 | 99久久精品免费视频 | 中文字幕在线观 | 免费视频一区二区 | 精品成人佐山爱一区二区 | 日本视频一区二区三区 | 中文字幕一区二区三区精彩视频 | 美国黄色毛片 | 成人视屏在线观看 | 久久久久久国模大尺度人体 | 日韩精品久久一区二区三区 | 国产精品自产拍 |