0

I guess the problem is layout, and I want to make the top line with the buttons in the Frame, Horizontal Layout;Below is the TabWidget with a table in it. The TabWidget and Frame use Vertical Layout.Previews in Qtdesigner are normal, but a BUG appears after the py file is converted. I made a smaller example to illustrate the problem. Here is the UI file code:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>1191</width>
    <height>941</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout_3">
   <item>
    <layout class="QVBoxLayout" name="verticalLayout_2">
     <item>
      <widget class="QFrame" name="frame">
       <property name="frameShape">
        <enum>QFrame::StyledPanel</enum>
       </property>
       <property name="frameShadow">
        <enum>QFrame::Raised</enum>
       </property>
       <layout class="QHBoxLayout" name="horizontalLayout">
        <item>
         <widget class="QPushButton" name="pushButton">
          <property name="text">
           <string>PushButton</string>
          </property>
         </widget>
        </item>
        <item>
         <widget class="QPushButton" name="pushButton_2">
          <property name="text">
           <string>PushButton</string>
          </property>
         </widget>
        </item>
        <item>
         <spacer name="horizontalSpacer">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
          </property>
          <property name="sizeHint" stdset="0">
           <size>
            <width>940</width>
            <height>20</height>
           </size>
          </property>
         </spacer>
        </item>
       </layout>
      </widget>
     </item>
     <item>
      <widget class="QTabWidget" name="tabWidget">
       <property name="tabPosition">
        <enum>QTabWidget::West</enum>
       </property>
       <property name="currentIndex">
        <number>0</number>
       </property>
       <widget class="QWidget" name="tab">
        <attribute name="title">
         <string>Tab 1</string>
        </attribute>
        <layout class="QVBoxLayout" name="verticalLayout">
         <item>
          <widget class="QTableWidget" name="tableWidget">
           <property name="rowCount">
            <number>5</number>
           </property>
           <row/>
           <row/>
           <row/>
           <row/>
           <row/>
           <column>
            <property name="text">
             <string>A</string>
            </property>
           </column>
           <column>
            <property name="text">
             <string>B</string>
            </property>
           </column>
           <column>
            <property name="text">
             <string>C</string>
            </property>
           </column>
           <column>
            <property name="text">
             <string>D</string>
            </property>
           </column>
          </widget>
         </item>
        </layout>
       </widget>
       <widget class="QWidget" name="tab_2">
        <attribute name="title">
         <string>Tab 2</string>
        </attribute>
       </widget>
      </widget>
     </item>
    </layout>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

I'm going to post some pictures, but I'm not sure I can, I've never uploaded pictures here...Orz. Here is a preview from Qtdesigner: designer preview

Here is the result that runs in the pycharm:

running screenshot

Here is the diagram:

inspector preview

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Johnc
  • 31
  • 6
  • It seems fine from here. Are you sure you're using the right ui file, and if you're using pyuic you've rebuilt it again after saving it? – musicamante Aug 18 '19 at 17:23
  • By S Nick's answer, the problem is solved.Thank you for taking time out of your busy schedule to help me – Johnc Aug 19 '19 at 04:00
  • 1
    if the answer given by SNick works for you, don't forget to mark it as accepted! Btw, remember to *always* provide [minimal, reproducible examples](https://stackoverflow.com/help/minimal-reproducible-example) in your answers: you were lucky that SNick did think about the wrong class inheritance possibility, but you can't always expect that level of "guessing" from other people... :-) – musicamante Aug 19 '19 at 04:13
  • Thanks for the advice, I'm just starting with Stack Overflow, so there's a lot of trouble.I'll pay attention later – Johnc Aug 20 '19 at 14:13

1 Answers1

2

change class MyApp(QtWidgets.QMainWindow, Ui_MainWindow): to class MyApp(QtWidgets.QWidget, Ui_MainWindow):

import sys
from PyQt5 import QtCore, QtGui, QtWidgets, uic

qtCreatorFile = "test22.ui"   
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)

#class MyApp(QtWidgets.QMainWindow, Ui_MainWindow):
class MyApp(QtWidgets.QWidget, Ui_MainWindow):
    def __init__(self):
        super().__init__()

        Ui_MainWindow.__init__(self)
        self.setupUi(self)

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    window = MyApp()
    window.show()
    sys.exit(app.exec_())

enter image description here

S. Nick
  • 12,879
  • 8
  • 25
  • 33