pyqt5滚动区域,如何添加标签

时间:2019-02-19 19:45:08

标签: python pyqt5

我为正在编写的代码在Qt创建器上创建了一个GUI界面,我几乎完成了该程序,但是我想通过在滚动区域中添加标签来显示滚动区域中列表中的计算结果。区域容器。通常要使用在Qt创建器上创建的任何内容,我要做的就是使用self.NameAddedInInterface调用它。我一直想做的就是这个

class MatplotlibWidget(QMainWindow):

    def __init__(self):
        self.m = TimeIndependent()
        QMainWindow.__init__(self)

        loadUi("UI.ui",self)

        self.setWindowTitle("PyQt5 & Matplotlib Example GUI")
        ## Results
        test = QLabel("god only knows")
        self.ContainerSimulated.addWidget(self.test)

        self.addToolBar(NavigationToolbar(self.MplWidget.canvas, self))
app = QApplication([])
window = MatplotlibWidget()
window.show()
app.exec_()

只需尝试向Qt创建器中创建的滚动区域添加标签。但是当我尝试运行时,我得到了:

Traceback (most recent call last):
  File "C:...\main.py", line 85, in <module>
    window = MatplotlibWidget()
  File "C:...\main.py", line 47, in __init__
    self.ContainerSimulated.addWidget(self.test)
AttributeError: 'QWidget' object has no attribute 'addWidget'

如何简单地将标签添加到滚动区域中以形成提示? 这是qtui文件

<?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>641</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <property name="minimumSize">
    <size>
     <width>800</width>
     <height>600</height>
    </size>
   </property>
   <layout class="QGridLayout" name="gridLayout_2">
    <item row="2" column="0">
     <layout class="QGridLayout" name="gridLayout">
      <item row="0" column="0">
       <widget class="QTabWidget" name="tabWidget">
        <property name="minimumSize">
         <size>
          <width>780</width>
          <height>175</height>
         </size>
        </property>
        <property name="maximumSize">
         <size>
          <width>16777215</width>
          <height>175</height>
         </size>
        </property>
        <property name="currentIndex">
         <number>3</number>
        </property>
        <widget class="QWidget" name="tab">
         <attribute name="title">
          <string>StepFunction</string>
         </attribute>
         <layout class="QGridLayout" name="gridLayout_5">
          <item row="0" column="0">
           <widget class="QLabel" name="label_3">
            <property name="text">
             <string>                Vmax</string>
            </property>
           </widget>
          </item>
          <item row="1" column="2">
           <widget class="QLabel" name="label_7">
            <property name="text">
             <string>                       B</string>
            </property>
           </widget>
          </item>
          <item row="2" column="3">
           <widget class="QPlainTextEdit" name="BoxSRange">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>29</height>
             </size>
            </property>
           </widget>
          </item>
          <item row="1" column="0">
           <widget class="QLabel" name="label_4">
            <property name="text">
             <string>                 Vmin</string>
            </property>
           </widget>
          </item>
          <item row="3" column="1">
           <widget class="QPushButton" name="PlotStepFunction">
            <property name="text">
             <string>Plot</string>
            </property>
           </widget>
          </item>
          <item row="1" column="1">
           <widget class="QPlainTextEdit" name="BoxVmin">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>29</height>
             </size>
            </property>
           </widget>
          </item>
          <item row="2" column="1">
           <widget class="QPlainTextEdit" name="BoxVo">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>29</height>
             </size>
            </property>
           </widget>
          </item>
          <item row="0" column="1">
           <widget class="QPlainTextEdit" name="BoxVmax">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>29</height>
             </size>
            </property>
           </widget>
          </item>
          <item row="1" column="3">
           <widget class="QPlainTextEdit" name="BoxLenB">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>29</height>
             </size>
            </property>
           </widget>
          </item>
          <item row="0" column="2">
           <widget class="QLabel" name="label_6">
            <property name="text">
             <string>                       A</string>
            </property>
           </widget>
          </item>
          <item row="2" column="0">
           <widget class="QLabel" name="label_5">
            <property name="text">
             <string>                    Vo</string>
            </property>
           </widget>
          </item>
          <item row="2" column="2">
           <widget class="QLabel" name="label_15">
            <property name="text">
             <string>              Range</string>
            </property>
           </widget>
          </item>
          <item row="0" column="3">
           <widget class="QPlainTextEdit" name="BoxLenA">
            <property name="maximumSize">
             <size>
              <width>150</width>
              <height>29</height>
             </size>
            </property>
           </widget>
          </item>
          <item row="0" column="5" rowspan="3">
           <widget class="QFrame" name="frame">
            <property name="frameShape">
             <enum>QFrame::StyledPanel</enum>
            </property>
            <property name="frameShadow">
             <enum>QFrame::Raised</enum>
            </property>
           </widget>
          </item>
          <item row="0" column="4" rowspan="4">
           <widget class="QLabel" name="PIc">
            <property name="minimumSize">
             <size>
              <width>60</width>
              <height>60</height>
             </size>
            </property>
            <property name="text">
             <string/>
            </property>
            <property name="pixmap">
             <pixmap>StepImage.jpg</pixmap>
            </property>
           </widget>
          </item>
         </layout>
        </widget>
        <widget class="QWidget" name="tab_2">
         <attribute name="title">
          <string>Quadratic</string>
         </attribute>
         <widget class="QWidget" name="gridLayoutWidget">
          <property name="geometry">
           <rect>
            <x>40</x>
            <y>10</y>
            <width>701</width>
            <height>121</height>
           </rect>
          </property>
          <layout class="QGridLayout" name="gridLayout_4">
           <item row="0" column="9">
            <widget class="QPlainTextEdit" name="BoxQB0">
             <property name="minimumSize">
              <size>
               <width>29</width>
               <height>29</height>
              </size>
             </property>
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>29</height>
              </size>
             </property>
            </widget>
           </item>
           <item row="0" column="1">
            <widget class="QTextEdit" name="BoxQB4">
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>29</height>
              </size>
             </property>
            </widget>
           </item>
           <item row="0" column="7">
            <widget class="QTextEdit" name="BoxQB1">
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>29</height>
              </size>
             </property>
            </widget>
           </item>
           <item row="0" column="8">
            <widget class="QLabel" name="label_12">
             <property name="text">
              <string>Ex°</string>
             </property>
            </widget>
           </item>
           <item row="0" column="4">
            <widget class="QLabel" name="label_10">
             <property name="text">
              <string>Cx²</string>
             </property>
            </widget>
           </item>
           <item row="0" column="0">
            <widget class="QLabel" name="label_9">
             <property name="text">
              <string>Ax4</string>
             </property>
            </widget>
           </item>
           <item row="0" column="3">
            <widget class="QPlainTextEdit" name="BoxQB3">
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>29</height>
              </size>
             </property>
            </widget>
           </item>
           <item row="0" column="6">
            <widget class="QLabel" name="label_11">
             <property name="text">
              <string>Dx¹</string>
             </property>
            </widget>
           </item>
           <item row="0" column="5">
            <widget class="QPlainTextEdit" name="BoxQB2">
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>29</height>
              </size>
             </property>
            </widget>
           </item>
           <item row="0" column="2">
            <widget class="QLabel" name="label_8">
             <property name="text">
              <string>Bx³</string>
             </property>
            </widget>
           </item>
           <item row="1" column="0">
            <widget class="QLabel" name="label_13">
             <property name="text">
              <string>Range</string>
             </property>
            </widget>
           </item>
           <item row="1" column="1">
            <widget class="QPlainTextEdit" name="BoxQXRange">
             <property name="maximumSize">
              <size>
               <width>16777215</width>
               <height>29</height>
              </size>
             </property>
            </widget>
           </item>
           <item row="1" column="7">
            <widget class="QPushButton" name="PlotQuadraticFunction">
             <property name="text">
              <string>Plot</string>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </widget>
        <widget class="QWidget" name="Schrodinger">
         <attribute name="title">
          <string>Schrodinger</string>
         </attribute>
         <layout class="QGridLayout" name="gridLayout_3">
          <item row="1" column="2">
           <spacer name="horizontalSpacer_3">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>40</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
          <item row="1" column="0">
           <widget class="QLabel" name="label_14">
            <property name="text">
             <string>                m=</string>
            </property>
           </widget>
          </item>
          <item row="1" column="1">
           <widget class="QPlainTextEdit" name="plainTextEdit">
            <property name="maximumSize">
             <size>
              <width>100</width>
              <height>29</height>
             </size>
            </property>
            <property name="plainText">
             <string>6.626068E-34</string>
            </property>
           </widget>
          </item>
          <item row="1" column="4">
           <spacer name="horizontalSpacer">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>40</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
          <item row="1" column="3">
           <spacer name="horizontalSpacer_2">
            <property name="orientation">
             <enum>Qt::Horizontal</enum>
            </property>
            <property name="sizeHint" stdset="0">
             <size>
              <width>40</width>
              <height>20</height>
             </size>
            </property>
           </spacer>
          </item>
          <item row="0" column="1">
           <widget class="QRadioButton" name="radioButton">
            <property name="text">
             <string>h^2/m =1</string>
            </property>
            <property name="checked">
             <bool>true</bool>
            </property>
           </widget>
          </item>
          <item row="2" column="1">
           <widget class="QPushButton" name="ButtonCalculate">
            <property name="text">
             <string>Calculate</string>
            </property>
           </widget>
          </item>
         </layout>
        </widget>
        <widget class="QWidget" name="tab_3">
         <attribute name="title">
          <string>Results</string>
         </attribute>
         <widget class="QWidget" name="horizontalLayoutWidget">
          <property name="geometry">
           <rect>
            <x>9</x>
            <y>29</y>
            <width>741</width>
            <height>91</height>
           </rect>
          </property>
          <layout class="QHBoxLayout" name="horizontalLayout_2">
           <item>
            <widget class="QScrollArea" name="scrollArea">
             <property name="widgetResizable">
              <bool>true</bool>
             </property>
             <widget class="QWidget" name="ContainerSimulated">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>0</y>
                <width>365</width>
                <height>87</height>
               </rect>
              </property>
             </widget>
            </widget>
           </item>
           <item>
            <widget class="QScrollArea" name="Theoretical">
             <property name="widgetResizable">
              <bool>true</bool>
             </property>
             <widget class="QWidget" name="scrollAreaWidgetContents_3">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>0</y>
                <width>364</width>
                <height>87</height>
               </rect>
              </property>
             </widget>
            </widget>
           </item>
          </layout>
         </widget>
         <widget class="QWidget" name="horizontalLayoutWidget_2">
          <property name="geometry">
           <rect>
            <x>10</x>
            <y>10</y>
            <width>741</width>
            <height>21</height>
           </rect>
          </property>
          <layout class="QHBoxLayout" name="horizontalLayout_3">
           <item>
            <widget class="QLabel" name="label_2">
             <property name="text">
              <string>Simulated Results</string>
             </property>
            </widget>
           </item>
           <item>
            <widget class="QLabel" name="label">
             <property name="text">
              <string>Theoretical</string>
             </property>
            </widget>
           </item>
          </layout>
         </widget>
        </widget>
       </widget>
      </item>
     </layout>
    </item>
    <item row="1" column="0">
     <widget class="MplWidget" name="MplWidget" native="true">
      <property name="minimumSize">
       <size>
        <width>400</width>
        <height>400</height>
       </size>
      </property>
     </widget>
    </item>
    <item row="0" column="0">
     <widget class="QLabel" name="Label_State">
      <property name="text">
       <string>State:</string>
      </property>
     </widget>
    </item>
   </layout>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>800</width>
     <height>21</height>
    </rect>
   </property>
   <widget class="QMenu" name="menuFile">
    <property name="title">
     <string>File</string>
    </property>
   </widget>
   <addaction name="menuFile"/>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <customwidgets>
  <customwidget>
   <class>MplWidget</class>
   <extends>QWidget</extends>
   <header>mplwidget.h</header>
   <container>1</container>
  </customwidget>
 </customwidgets>
 <resources/>
 <connections/>
</ui>

0 个答案:

没有答案