I'm trying to break away from having all my widgets and my main window in one user interface file. So in the example below I've created a frame that I want to show up in the main window. Later on I will show and hide it along with other frames etc. It pops up but in its own window and only briefly. What am I doing wrong? How do I get the QFrame UI file I created in Qt Designer to behave like what I would expect? That is to say a frame and not frame inside a window? I've excluded the boilerplate code that pyuic4 generates.
myApp.py:
import sys
from PyQt4 import QtCore, QtGui
from main_window import Ui_MainWindow
from frame2 import Frame
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
myFrame = Frame()
myFrame.show()
if __name__ == "__main__":
mainWin = StartQt4()
mainWin.show()
sys.exit(app.exec_())
import sys
from PyQt4 import QtCore, QtGui
from main_window import Ui_MainWindow
from frame2 import Frame
class StartQt4(QtGui.QMainWindow, Ui_MainWindow):
def __init__(self):
super(self.__class__, self).__init__()
self.setupUi(self)
myFrame = Frame()
myFrame.show()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mainWin = StartQt4()
mainWin.show()
sys.exit(app.exec_())
To copy to clipboard, switch view to plain text mode
main_window.py:
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(640, 480)
self.
centralwidget = QtGui.
QWidget(MainWindow
) self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.
label = QtGui.
QLabel(self.
centralwidget) self.
label.
setGeometry(QtCore.
QRect(155,
45,
146,
81)) self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label.setText(_translate("MainWindow", "Main Window without menu bar", None))
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(640, 480)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.label = QtGui.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(155, 45, 146, 81))
self.label.setObjectName(_fromUtf8("label"))
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName(_fromUtf8("statusbar"))
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
self.label.setText(_translate("MainWindow", "Main Window without menu bar", None))
To copy to clipboard, switch view to plain text mode
frame2.py:
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName(_fromUtf8("Frame"))
Frame.resize(320, 240)
Frame.
setFrameShape(QtGui.
QFrame.
Box) Frame.
setFrameShadow(QtGui.
QFrame.
Plain) Frame.setLineWidth(8)
self.
label = QtGui.
QLabel(Frame
) self.
label.
setGeometry(QtCore.
QRect(100,
60,
141,
76)) self.label.setObjectName(_fromUtf8("label"))
self.retranslateUi(Frame)
def retranslateUi(self, Frame):
Frame.setWindowTitle(_translate("Frame", "Frame", None))
self.label.setText(_translate("Frame", "This is the frame", None))
class Frame
(QtGui.
QFrame, Ui_Frame
): def __init__(self, parent=None, f=QtCore.Qt.WindowFlags()):
QtGui.
QFrame.__init__
(self, parent, f
)
self.setupUi(self)
class Ui_Frame(object):
def setupUi(self, Frame):
Frame.setObjectName(_fromUtf8("Frame"))
Frame.resize(320, 240)
Frame.setFrameShape(QtGui.QFrame.Box)
Frame.setFrameShadow(QtGui.QFrame.Plain)
Frame.setLineWidth(8)
self.label = QtGui.QLabel(Frame)
self.label.setGeometry(QtCore.QRect(100, 60, 141, 76))
self.label.setObjectName(_fromUtf8("label"))
self.retranslateUi(Frame)
QtCore.QMetaObject.connectSlotsByName(Frame)
def retranslateUi(self, Frame):
Frame.setWindowTitle(_translate("Frame", "Frame", None))
self.label.setText(_translate("Frame", "This is the frame", None))
class Frame(QtGui.QFrame, Ui_Frame):
def __init__(self, parent=None, f=QtCore.Qt.WindowFlags()):
QtGui.QFrame.__init__(self, parent, f)
self.setupUi(self)
To copy to clipboard, switch view to plain text mode
Bookmarks