У меня есть QMainWindow с меню и mdiArea. Когда я нажимаю на элемент меню, мне нужно отобразить qDialog, скажем, с одним из них.
Я бы хотел построить QDialog с использованием списка данных как его собственного класса; Однако я не знаю, как прикрепить его к mdiArea в качестве подокна. Можно ли получить небольшой пример того, как это сделать?
import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QMainWindow
from PyQt5.uic import loadUi
class CliDataBrowser(QDialog):
def __init__(self,parent=None):
super(CliDataBrowser,self).__init__(parent)
loadUi("CliReportsUI/clidata_browser.ui",self)
class MainApplication(QMainWindow):
def __init__(self,*args):
super(MainApplication,self).__init__(*args)
loadUi("CliReportsUI/clireportmain.ui",self)
@pyqtSlot()
def on_mnu_close_triggered(self):
sys.exit();
@pyqtSlot()
def on_mnu_master_triggered(self):
dataBrowser = CliDataBrowser(self) # <--- Need this to be a mdi subwindow
dataBrowser.show()
app = QApplication(sys.argv)
mainWin = MainApplication()
mainWin.show()
sys.exit(app.exec_())
clireportmain.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CliReportMain</class>
<widget class="QMainWindow" name="CliReportMain">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1062</width>
<height>626</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>PPS Custom Client Reports</string>
</property>
<property name="windowIcon">
<iconset resource="clireports.qrc">
<normaloff>:/Images/clireports.png</normaloff>:/Images/clireports.png</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QMdiArea" name="mdiArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="background">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>20</red>
<green>38</green>
<blue>57</blue>
</color>
</brush>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>1062</width>
<height>22</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="mnu_Close"/>
</widget>
<widget class="QMenu" name="menuReports">
<property name="title">
<string>Reports</string>
</property>
</widget>
<widget class="QMenu" name="menuDatasets">
<property name="title">
<string>Datasets</string>
</property>
<addaction name="mnu_Master"/>
<addaction name="mnu_ICD10Master"/>
<addaction name="separator"/>
<addaction name="mnu_ProviderMaster"/>
<addaction name="mnu_InsuranceMaster"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuReports"/>
<addaction name="menuDatasets"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="mnu_Close">
<property name="text">
<string>Close</string>
</property>
</action>
<action name="mnu_Master">
<property name="text">
<string>Master</string>
</property>
</action>
<action name="mnu_ICD10Master">
<property name="text">
<string>ICD-10 Master</string>
</property>
</action>
<action name="mnu_ProviderMaster">
<property name="text">
<string>Provider Master</string>
</property>
</action>
<action name="mnu_InsuranceMaster">
<property name="text">
<string>Insurance Master</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="clireports.qrc"/>
</resources>
<connections/>
</ui>