Created
July 4, 2012 20:13
-
-
Save fmorency/3049311 to your computer and use it in GitHub Desktop.
Create GUI from .ui files. Events do not propagate correctly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PySide.QtCore.QEvent.Type.ChildAdded <PySide.QtGui.QFrame object at 0x17787a0> | |
PySide.QtCore.QEvent.Type.ChildAdded <PySide.QtGui.QFrame object at 0x17787e8> | |
PySide.QtCore.QEvent.Type.ParentChange <PySide.QtGui.QFrame object at 0x17787a0> | |
PySide.QtCore.QEvent.Type.Polish <PySide.QtGui.QFrame object at 0x17787a0> | |
PySide.QtCore.QEvent.Type(70) <PySide.QtGui.QFrame object at 0x17787a0> | |
PySide.QtCore.QEvent.Type.ParentChange <PySide.QtGui.QFrame object at 0x17787e8> | |
PySide.QtCore.QEvent.Type.Polish <PySide.QtGui.QFrame object at 0x17787e8> | |
PySide.QtCore.QEvent.Type(70) <PySide.QtGui.QFrame object at 0x17787e8> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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>600</height> | |
</rect> | |
</property> | |
<property name="windowTitle"> | |
<string>MainWindow</string> | |
</property> | |
<widget class="QWidget" name="centralwidget"> | |
<layout class="QHBoxLayout" name="horizontalLayout_2"> | |
<item> | |
<layout class="QHBoxLayout" name="horizontalLayout"> | |
<item> | |
<widget class="QMdiArea" name="mdiArea"/> | |
</item> | |
</layout> | |
</item> | |
</layout> | |
</widget> | |
</widget> | |
<resources> | |
<include location="../resources.qrc"/> | |
</resources> | |
<connections/> | |
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from ui.uiloader import UiLoader | |
class CloseEventFilter(QObject): | |
def eventFilter(self, target, event): | |
print event.type(), target | |
return False | |
class MainWindow(QMainWindow): | |
def __init__(self, parent=None, wflags=Qt.WindowFlags()): | |
super(MainWindow, self).__init__(parent, wflags) | |
UiLoader.loadUi(self, ':/UI/ui/main_window.ui') | |
mdi_area = self.findChild(QMdiArea, 'mdiArea') | |
ev_filter = CloseEventFilter() | |
qframe1 = QFrame(self) | |
qframe2 = QFrame(self) | |
qframe1.installEventFilter(ev_filter) | |
qframe2.installEventFilter(ev_filter) | |
qhbox1 = QHBoxLayout(qframe1) | |
qhbox2 = QHBoxLayout(qframe2) | |
qframe1.setLayout(qhbox1) | |
sw1 = mdi_area.addSubWindow(qframe1, Qt.WA_DeleteOnClose) | |
qframe2.setLayout(qhbox2) | |
sw2 = mdi_area.addSubWindow(qframe2, Qt.WA_DeleteOnClose) | |
QtGui.qApp.lastWindowClosed.connect(lambda: mdi_area.closeAllSubWindows()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<RCC> | |
<qresource prefix="UI"> | |
<file>ui/main_window.ui</file> | |
</qresource> | |
</RCC> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
from PySide.QtCore import * | |
from PySide.QtGui import * | |
from PySide.QtXml import * | |
from PySide.QtUiTools import * | |
from ui.MainWindow import MainWindow | |
if __name__ == '__main__': | |
app = QApplication(sys.argv) | |
resource_abs_file = os.path.join( | |
os.path.realpath( | |
os.path.dirname(sys.argv[0] | |
) | |
), 'resources/resources.rcc') | |
if not QResource.registerResource(resource_abs_file): | |
raise IOError('Enable to load resource file: ', resource_abs_file) | |
main_window = MainWindow() | |
main_window.show() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment