2011-08-23 16 views
5

के साथ सरल फ़ॉर्म बनाना I pyqt में अपना पहला एप्लिकेशन चलाने की कोशिश कर रहा हूं। जब मैं डिजाइनर में पूर्वावलोकन कर रहा हूँ मेरे प्रपत्र ठीक लग रहा है:क्यूटी-डिजाइनर और pyqt

http://imageshack.us/photo/my-images/171/screenshotuw.png/

लेकिन अगर मैं इसे अपने स्क्रिप्ट से दिखा रहा हूँ मुझे मिल गया:

http://imageshack.us/photo/my-images/268/screenshot1hwn.png/

और टर्मिनल में जानकारी: QLayout: MyForm "फॉर्म" में QLayout "" जोड़ने का प्रयास कर रहा है, जिसमें पहले से ही एक लेआउट

प्रश्न है, मेरे डिजाइन में क्या गलत है?

pyuic4 द्वारा

जनरेट किया गया फ़ाइल:

# -*- coding: utf-8 -*- 

# Form implementation generated from reading ui file 'gui.ui' 
# 
# Created: Tue Aug 23 11:17:30 2011 
#  by: PyQt4 UI code generator 4.7.2 
# 
# WARNING! All changes made in this file will be lost! 

from PyQt4 import QtCore, QtGui 

class Ui_Form(object): 
    def setupUi(self, Form): 
    Form.setObjectName("Form") 
    Form.resize(464, 409) 
    self.verticalLayout_2 = QtGui.QVBoxLayout(Form) 
    self.verticalLayout_2.setObjectName("verticalLayout_2") 
    self.horizontalLayout = QtGui.QHBoxLayout() 
    self.horizontalLayout.setObjectName("horizontalLayout") 
    self.listView = QtGui.QListView(Form) 
    self.listView.setObjectName("listView") 
    self.horizontalLayout.addWidget(self.listView) 
    self.verticalLayout = QtGui.QVBoxLayout() 
    self.verticalLayout.setObjectName("verticalLayout") 
    self.pushButton = QtGui.QPushButton(Form) 
    self.pushButton.setObjectName("pushButton") 
    self.verticalLayout.addWidget(self.pushButton) 
    self.pushButton_2 = QtGui.QPushButton(Form) 
    self.pushButton_2.setObjectName("pushButton_2") 
    self.verticalLayout.addWidget(self.pushButton_2) 
    spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) 
    self.verticalLayout.addItem(spacerItem) 
    self.pushButton_3 = QtGui.QPushButton(Form) 
    self.pushButton_3.setObjectName("pushButton_3") 
    self.verticalLayout.addWidget(self.pushButton_3) 
    self.horizontalLayout.addLayout(self.verticalLayout) 
    self.verticalLayout_2.addLayout(self.horizontalLayout) 
    self.textBrowser = QtGui.QTextBrowser(Form) 
    self.textBrowser.setObjectName("textBrowser") 
    self.verticalLayout_2.addWidget(self.textBrowser) 

    self.retranslateUi(Form) 
    QtCore.QMetaObject.connectSlotsByName(Form) 

    def retranslateUi(self, Form): 
    Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8)) 
    self.pushButton.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8)) 
    self.pushButton_2.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8)) 
    self.pushButton_3.setText(QtGui.QApplication.translate("Form", "PushButton", None, QtGui.QApplication.UnicodeUTF8)) 

और मेरी स्क्रिप्ट जो इसे उपयोग कर रहा है: आयात sys PyQt4 आयात QtCore से, QtGui

from gen import Ui_Form 


    class MyForm(QtGui.QMainWindow): 
     def __init__(self, parent=None): 
      QtGui.QWidget.__init__(self, parent) 
      self.ui = Ui_Form() 
      self.ui.setupUi(self) 
     def execute_event(self): 
      pass 
     def execute_all_event(self): 
      pass 
     def reload_event(self): 
      pass 

    if __name__ == "__main__": 
     app = QtGui.QApplication(sys.argv) 
     myapp = MyForm() 
     myapp.show() 
     sys.exit(app.exec_()) 

मैं प्रपत्र बनाया डिजाइनर का उपयोग कर और मैं जीयूआई मिला .ui फ़ाइल:

<?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>464</width> 
    <height>409</height> 
    </rect> 
    </property> 
    <property name="windowTitle"> 
    <string>Form</string> 
    </property> 
    <layout class="QVBoxLayout" name="verticalLayout_2"> 
    <item> 
    <layout class="QHBoxLayout" name="horizontalLayout"> 
    <item> 
     <widget class="QListView" name="listView"/> 
    </item> 
    <item> 
     <layout class="QVBoxLayout" name="verticalLayout"> 
     <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="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_3"> 
    <property name="text"> 
     <string>PushButton</string> 
    </property> 
    </widget> 
     </item> 
     </layout> 
    </item> 
    </layout> 
    </item> 
    <item> 
    <widget class="QTextBrowser" name="textBrowser"/> 
    </item> 
    </layout> 
</widget> 
<resources/> 
<connections/> 
</ui> 

उत्तर

12

मैं कहूंगा कि आपने डिजाइनर में QWidget डिज़ाइन किया है, और आप QMainWindow बनाते हैं।

class MyForm(QtGui.QWidget) 
+0

बिल्कुल द्वारा

class MyForm(QtGui.QMainWindow) 

बदलें! धन्यवाद। – Adam

 संबंधित मुद्दे