#include "mdi.h"#include "ui_mdi.h"#include "childw.h"mdi::mdi(QWidget *parent) : QMainWindow(parent), ui(new Ui::mdi){ ui->setupUi(this);............. connect(ui->actionLoad,SIGNAL(triggered()),this,SLOT(slotLoad()));............. connect(ui->mdiArea,SIGNAL(subWindowActivated(QMdiSubWindow*)),this,SLOT(changeTitle()));}.............void mdi::slotLoad(){ childw* pdoc=createNewDoc(); pdoc->slotLoad(); this->setWindowTitle(pdoc->windowTitle()); pdoc->show();}.............void mdi::changeTitle(){ this->setWindowTitle(ui->mdiArea->activeSubWindow()->windowTitle());}
..............void childw::slotLoad(){ QString str=QFileDialog::getOpenFileName(); if(str.isEmpty()) return; QFile file(str); if(!file.open(QFile::ReadOnly)) { QMessageBox::warning(this,tr("Ошибка открытия"),tr("Не удается открыть файл %1").arg(str)); return; } QTextStream instream(&file); ui->textEdit->setPlainText(instream.readAll()); file.close(); this->changeTitle(str);}
connect(ui->mdiArea,SIGNAL(subWindowActivated(QMdiSubWindow*)),this,SLOT(changeTitle()));
void mdi::changeTitle(){ QMdiSubWindow *pSubWin = ui->mdiArea->activeSubWindow(); if( pSubWin ) { this->setWindowTitle(pSubWin->windowTitle()); }}