#include #include #include #include #include #include #include #include class View: public QWidget{ Q_OBJECT public: View(QWidget *parent=0): QWidget(parent){ QVBoxLayout *vlayout=new QVBoxLayout(this); QHBoxLayout *layout=new QHBoxLayout(this); vlayout->addLayout(layout); __storeButton=new QPushButton(tr(" Store"),this); restoreButton=new QPushButton(tr("Restore"),this); layout->addWidget(__storeButton); layout->addWidget(restoreButton); connect(__storeButton,SIGNAL(clicked()),SLOT( store())); connect(restoreButton,SIGNAL(clicked()),SLOT(restore())); textBrowser=new QTextBrowser(this); textBrowser->setLineWrapMode(QTextEdit::NoWrap); QFont font("Courier"); font.setStyleHint(QFont::TypeWriter); textBrowser->setFont(font); vlayout->addWidget(textBrowser); } public slots: void store(){ buf=sub()->saveGeometry(); restoreButton->setEnabled( !buf.isEmpty() ); updateText(); } void restore(){ sub()->restoreGeometry(buf); } void updateText(){ const int max=8; int newLine; int i,j; newLine=1; QString text; for(i=0;i=buf.length()) break; //text.append( buf.data()[i+j]>32?buf.data()[i+j]:' '); } i+=max; } textBrowser->setText(text); } protected: inline QMdiSubWindow *sub(){ QMdiSubWindow *sub=qobject_cast( parent() ); Q_ASSERT(sub); return sub; } QByteArray buf; QPushButton *__storeButton; QPushButton *restoreButton; QTextBrowser *textBrowser; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QMainWindow main; QMdiArea mdiArea(&main); mdiArea.setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); mdiArea.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); main.setCentralWidget(&mdiArea); main.resize(400,300); QMdiSubWindow sub(&mdiArea); mdiArea.addSubWindow(&sub); View view(&mdiArea); sub.setWidget(&view); //sub.setGeometry(QRect(30,50,200,100)); main.show(); return a.exec(); } #include "moc_main.cpp"